New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@middy/http-response-serializer

Package Overview
Dependencies
Maintainers
3
Versions
197
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@middy/http-response-serializer - npm Package Compare versions

Comparing version 2.0.0-alpha.5 to 2.0.0-alpha.6

26

index.js
"use strict";
const {
normalizeHttpResponse
} = require('@middy/util');
const Accept = require('@hapi/accept');

@@ -7,3 +11,3 @@

module.exports = (opts = {}) => {
const httpResponseSerializerMiddleware = (opts = {}) => {
const options = { ...defaults,

@@ -14,7 +18,8 @@ ...opts

const httpResponseSerializerMiddlewareAfter = async handler => {
var _handler$event$header, _handler$event, _handler$response$hea, _handler$response;
var _handler$event$header, _handler$event;
// normalise headers for internal use only
const requestHeaders = getNormalisedHeaders((_handler$event$header = (_handler$event = handler.event) === null || _handler$event === void 0 ? void 0 : _handler$event.headers) !== null && _handler$event$header !== void 0 ? _handler$event$header : {});
const responseHeaders = getNormalisedHeaders((_handler$response$hea = (_handler$response = handler.response) === null || _handler$response === void 0 ? void 0 : _handler$response.headers) !== null && _handler$response$hea !== void 0 ? _handler$response$hea : {}); // skip serialization when content-type is already set
handler.response = normalizeHttpResponse(handler.response);
const responseHeaders = getNormalisedHeaders(handler.response.headers); // skip serialization when content-type is already set

@@ -42,4 +47,2 @@ if (responseHeaders['content-type']) {

types.find(type => options.serializers.find(s => {
var _handler$response$hea2, _handler$response2;
const test = s.regex.test(type);

@@ -49,14 +52,7 @@

return false;
} // if the response is not an object, assign it to body. { body: undefined } is not serialized
} // set header
handler.response = handler.response !== null && typeof handler.response === 'object' ? handler.response : {
body: handler.response
}; // set header
handler.response.headers['Content-Type'] = type; // run serializer
handler.response.headers = (_handler$response$hea2 = (_handler$response2 = handler.response) === null || _handler$response2 === void 0 ? void 0 : _handler$response2.headers) !== null && _handler$response$hea2 !== void 0 ? _handler$response$hea2 : {};
handler.response.headers = { ...handler.response.headers,
'Content-Type': type
}; // run serializer
const result = s.serializer(handler.response);

@@ -87,1 +83,3 @@

}, {});
module.exports = httpResponseSerializerMiddleware;
{
"name": "@middy/http-response-serializer",
"version": "2.0.0-alpha.5",
"version": "2.0.0-alpha.6",
"description": "The Http Serializer middleware lets you define serialization mechanisms based on the current content negotiation.",

@@ -54,5 +54,6 @@ "type": "commonjs",

"@hapi/accept": "5.0.1",
"@middy/util": "^2.0.0-alpha.6",
"http-errors": "1.8.0"
},
"gitHead": "2e69ea2322abcdcf88adde11fda4d04e4c038b54"
"gitHead": "e6ab94a1f33ca215f63ee613bc9469ccd56caf21"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc