@middy/http-multipart-body-parser 4.6.1 → 4.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.cjs +6 -2
  2. package/index.js +5 -1
  3. package/package.json +4 -4
package/index.cjs CHANGED
@@ -8,7 +8,7 @@ Object.defineProperty(module, "exports", {
8
8
  return _default;
9
9
  }
10
10
  });
11
- const _busboy = _interop_require_default(require("busboy"));
11
+ const _busboy = /*#__PURE__*/ _interop_require_default(require("busboy"));
12
12
  const _util = require("@middy/util");
13
13
  function _interop_require_default(obj) {
14
14
  return obj && obj.__esModule ? obj : {
@@ -18,6 +18,7 @@ function _interop_require_default(obj) {
18
18
  const mimePattern = /^multipart\/form-data(;.*)?$/;
19
19
  const fieldnamePattern = /(.+)\[(.*)]$/;
20
20
  const defaults = {
21
+ // busboy options as per documentation: https://www.npmjs.com/package/busboy#busboy-methods
21
22
  busboy: {},
22
23
  charset: 'utf8',
23
24
  disableContentTypeError: true
@@ -29,7 +30,7 @@ const httpMultipartBodyParserMiddleware = (opts = {})=>{
29
30
  };
30
31
  const httpMultipartBodyParserMiddlewareBefore = async (request)=>{
31
32
  const { headers } = request.event;
32
- const contentType = headers['Content-Type'] ?? headers['content-type'];
33
+ const contentType = headers?.['Content-Type'] ?? headers?.['content-type'];
33
34
  if (!mimePattern.test(contentType)) {
34
35
  if (options.disableContentTypeError) {
35
36
  return;
@@ -39,8 +40,10 @@ const httpMultipartBodyParserMiddleware = (opts = {})=>{
39
40
  });
40
41
  }
41
42
  return parseMultipartData(request.event, options).then((multipartData)=>{
43
+ // request.event.rawBody = body
42
44
  request.event.body = multipartData;
43
45
  }).catch((cause)=>{
46
+ // UnprocessableEntity
44
47
  throw (0, _util.createError)(415, 'Invalid or malformed multipart/form-data was provided', {
45
48
  cause
46
49
  });
@@ -53,6 +56,7 @@ const httpMultipartBodyParserMiddleware = (opts = {})=>{
53
56
  const parseMultipartData = (event, options)=>{
54
57
  const multipartData = {};
55
58
  const charset = event.isBase64Encoded ? 'base64' : options.charset;
59
+ // header must be lowercase (content-type)
56
60
  const busboy = (0, _busboy.default)({
57
61
  ...options.busboy,
58
62
  headers: {
package/index.js CHANGED
@@ -3,6 +3,7 @@ import { createError } from '@middy/util';
3
3
  const mimePattern = /^multipart\/form-data(;.*)?$/;
4
4
  const fieldnamePattern = /(.+)\[(.*)]$/;
5
5
  const defaults = {
6
+ // busboy options as per documentation: https://www.npmjs.com/package/busboy#busboy-methods
6
7
  busboy: {},
7
8
  charset: 'utf8',
8
9
  disableContentTypeError: true
@@ -14,7 +15,7 @@ const httpMultipartBodyParserMiddleware = (opts = {})=>{
14
15
  };
15
16
  const httpMultipartBodyParserMiddlewareBefore = async (request)=>{
16
17
  const { headers } = request.event;
17
- const contentType = headers['Content-Type'] ?? headers['content-type'];
18
+ const contentType = headers?.['Content-Type'] ?? headers?.['content-type'];
18
19
  if (!mimePattern.test(contentType)) {
19
20
  if (options.disableContentTypeError) {
20
21
  return;
@@ -24,8 +25,10 @@ const httpMultipartBodyParserMiddleware = (opts = {})=>{
24
25
  });
25
26
  }
26
27
  return parseMultipartData(request.event, options).then((multipartData)=>{
28
+ // request.event.rawBody = body
27
29
  request.event.body = multipartData;
28
30
  }).catch((cause)=>{
31
+ // UnprocessableEntity
29
32
  throw createError(415, 'Invalid or malformed multipart/form-data was provided', {
30
33
  cause
31
34
  });
@@ -38,6 +41,7 @@ const httpMultipartBodyParserMiddleware = (opts = {})=>{
38
41
  const parseMultipartData = (event, options)=>{
39
42
  const multipartData = {};
40
43
  const charset = event.isBase64Encoded ? 'base64' : options.charset;
44
+ // header must be lowercase (content-type)
41
45
  const busboy = BusBoy({
42
46
  ...options.busboy,
43
47
  headers: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-multipart-body-parser",
3
- "version": "4.6.1",
3
+ "version": "4.6.3",
4
4
  "description": "Http event normalizer middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -66,13 +66,13 @@
66
66
  "url": "https://github.com/sponsors/willfarrell"
67
67
  },
68
68
  "dependencies": {
69
- "@middy/util": "4.6.1",
69
+ "@middy/util": "4.6.3",
70
70
  "busboy": "1.6.0"
71
71
  },
72
72
  "devDependencies": {
73
- "@middy/core": "4.6.1",
73
+ "@middy/core": "4.6.3",
74
74
  "@types/aws-lambda": "^8.10.101",
75
75
  "type-fest": "^4.0.0"
76
76
  },
77
- "gitHead": "253ed0e4ca95623decbade03938a07d837a1eba2"
77
+ "gitHead": "4873f6e64cc4a7dbe8739ed3e45ef458dfe0dba1"
78
78
  }