@middy/http-multipart-body-parser 4.0.9 → 4.1.0

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.
package/index.cjs CHANGED
@@ -17,7 +17,8 @@ const mimePattern = /^multipart\/form-data(;.*)?$/;
17
17
  const fieldnamePattern = /(.+)\[(.*)]$/;
18
18
  const defaults = {
19
19
  busboy: {},
20
- charset: 'utf8'
20
+ charset: 'utf8',
21
+ disableContentTypeError: true
21
22
  };
22
23
  const httpMultipartBodyParserMiddleware = (opts = {})=>{
23
24
  const options = {
@@ -27,11 +28,18 @@ const httpMultipartBodyParserMiddleware = (opts = {})=>{
27
28
  const httpMultipartBodyParserMiddlewareBefore = async (request)=>{
28
29
  const { headers } = request.event;
29
30
  const contentType = headers['Content-Type'] ?? headers['content-type'];
30
- if (!mimePattern.test(contentType)) return;
31
+ if (!mimePattern.test(contentType)) {
32
+ if (options.disableContentTypeError) {
33
+ return;
34
+ }
35
+ throw (0, _util.createError)(415, '@middy/http-multipart-body-parser Unsupported Media Type', {
36
+ cause: contentType
37
+ });
38
+ }
31
39
  return parseMultipartData(request.event, options).then((multipartData)=>{
32
40
  request.event.body = multipartData;
33
41
  }).catch((cause)=>{
34
- throw (0, _util.createError)(422, 'Invalid or malformed multipart/form-data was provided', {
42
+ throw (0, _util.createError)(415, 'Invalid or malformed multipart/form-data was provided', {
35
43
  cause
36
44
  });
37
45
  });
package/index.d.ts CHANGED
@@ -20,6 +20,7 @@ interface Options {
20
20
  }
21
21
  }
22
22
  charset?: string
23
+ disableContentTypeError?: boolean
23
24
  }
24
25
 
25
26
  export type Event = Omit<APIGatewayEvent, 'body'> & {
package/index.js CHANGED
@@ -4,7 +4,8 @@ const mimePattern = /^multipart\/form-data(;.*)?$/;
4
4
  const fieldnamePattern = /(.+)\[(.*)]$/;
5
5
  const defaults = {
6
6
  busboy: {},
7
- charset: 'utf8'
7
+ charset: 'utf8',
8
+ disableContentTypeError: true
8
9
  };
9
10
  const httpMultipartBodyParserMiddleware = (opts = {})=>{
10
11
  const options = {
@@ -14,11 +15,18 @@ const httpMultipartBodyParserMiddleware = (opts = {})=>{
14
15
  const httpMultipartBodyParserMiddlewareBefore = async (request)=>{
15
16
  const { headers } = request.event;
16
17
  const contentType = headers['Content-Type'] ?? headers['content-type'];
17
- if (!mimePattern.test(contentType)) return;
18
+ if (!mimePattern.test(contentType)) {
19
+ if (options.disableContentTypeError) {
20
+ return;
21
+ }
22
+ throw createError(415, '@middy/http-multipart-body-parser Unsupported Media Type', {
23
+ cause: contentType
24
+ });
25
+ }
18
26
  return parseMultipartData(request.event, options).then((multipartData)=>{
19
27
  request.event.body = multipartData;
20
28
  }).catch((cause)=>{
21
- throw createError(422, 'Invalid or malformed multipart/form-data was provided', {
29
+ throw createError(415, 'Invalid or malformed multipart/form-data was provided', {
22
30
  cause
23
31
  });
24
32
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-multipart-body-parser",
3
- "version": "4.0.9",
3
+ "version": "4.1.0",
4
4
  "description": "Http event normalizer middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -62,13 +62,13 @@
62
62
  },
63
63
  "homepage": "https://middy.js.org",
64
64
  "dependencies": {
65
- "@middy/util": "4.0.9",
65
+ "@middy/util": "4.1.0",
66
66
  "busboy": "1.6.0"
67
67
  },
68
68
  "devDependencies": {
69
- "@middy/core": "4.0.9",
69
+ "@middy/core": "4.1.0",
70
70
  "@types/aws-lambda": "^8.10.101",
71
71
  "type-fest": "^3.0.0"
72
72
  },
73
- "gitHead": "02210765f9154584c242e4440d086abcf3321028"
73
+ "gitHead": "c5abbac9280c3a2f30758188233a7b27367901d1"
74
74
  }