@wooksjs/http-body 0.2.4 → 0.2.5
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/dist/index.cjs +4 -4
- package/dist/index.mjs +5 -5
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -100,7 +100,7 @@ function useBody() {
|
|
|
100
100
|
return JSON.parse(v);
|
|
101
101
|
}
|
|
102
102
|
catch (e) {
|
|
103
|
-
throw new eventHttp.
|
|
103
|
+
throw new eventHttp.HttpError(400, e.message);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
function textParser(v) {
|
|
@@ -109,7 +109,7 @@ function useBody() {
|
|
|
109
109
|
function formDataParser(v) {
|
|
110
110
|
const boundary = '--' + (/boundary=([^;]+)(?:;|$)/.exec(contentType || '') || [, ''])[1];
|
|
111
111
|
if (!boundary)
|
|
112
|
-
throw new eventHttp.
|
|
112
|
+
throw new eventHttp.HttpError(eventHttp.EHttpStatusCode.BadRequest, 'form-data boundary not recognized');
|
|
113
113
|
const parts = v.trim().split(boundary);
|
|
114
114
|
const result = {};
|
|
115
115
|
let key = '';
|
|
@@ -140,13 +140,13 @@ function useBody() {
|
|
|
140
140
|
if (line.toLowerCase().startsWith('content-disposition: form-data;')) {
|
|
141
141
|
key = (/name=([^;]+)/.exec(line) || [])[1];
|
|
142
142
|
if (!key)
|
|
143
|
-
throw new eventHttp.
|
|
143
|
+
throw new eventHttp.HttpError(eventHttp.EHttpStatusCode.BadRequest, 'Could not read multipart name: ' + line);
|
|
144
144
|
continue;
|
|
145
145
|
}
|
|
146
146
|
if (line.toLowerCase().startsWith('content-type:')) {
|
|
147
147
|
partContentType = (/content-type:\s?([^;]+)/i.exec(line) || [])[1];
|
|
148
148
|
if (!partContentType)
|
|
149
|
-
throw new eventHttp.
|
|
149
|
+
throw new eventHttp.HttpError(eventHttp.EHttpStatusCode.BadRequest, 'Could not read content-type: ' + line);
|
|
150
150
|
continue;
|
|
151
151
|
}
|
|
152
152
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useHttpContext, useRequest, useHeaders,
|
|
1
|
+
import { useHttpContext, useRequest, useHeaders, HttpError, EHttpStatusCode, WooksURLSearchParams } from '@wooksjs/event-http';
|
|
2
2
|
|
|
3
3
|
/******************************************************************************
|
|
4
4
|
Copyright (c) Microsoft Corporation.
|
|
@@ -98,7 +98,7 @@ function useBody() {
|
|
|
98
98
|
return JSON.parse(v);
|
|
99
99
|
}
|
|
100
100
|
catch (e) {
|
|
101
|
-
throw new
|
|
101
|
+
throw new HttpError(400, e.message);
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
function textParser(v) {
|
|
@@ -107,7 +107,7 @@ function useBody() {
|
|
|
107
107
|
function formDataParser(v) {
|
|
108
108
|
const boundary = '--' + (/boundary=([^;]+)(?:;|$)/.exec(contentType || '') || [, ''])[1];
|
|
109
109
|
if (!boundary)
|
|
110
|
-
throw new
|
|
110
|
+
throw new HttpError(EHttpStatusCode.BadRequest, 'form-data boundary not recognized');
|
|
111
111
|
const parts = v.trim().split(boundary);
|
|
112
112
|
const result = {};
|
|
113
113
|
let key = '';
|
|
@@ -138,13 +138,13 @@ function useBody() {
|
|
|
138
138
|
if (line.toLowerCase().startsWith('content-disposition: form-data;')) {
|
|
139
139
|
key = (/name=([^;]+)/.exec(line) || [])[1];
|
|
140
140
|
if (!key)
|
|
141
|
-
throw new
|
|
141
|
+
throw new HttpError(EHttpStatusCode.BadRequest, 'Could not read multipart name: ' + line);
|
|
142
142
|
continue;
|
|
143
143
|
}
|
|
144
144
|
if (line.toLowerCase().startsWith('content-type:')) {
|
|
145
145
|
partContentType = (/content-type:\s?([^;]+)/i.exec(line) || [])[1];
|
|
146
146
|
if (!partContentType)
|
|
147
|
-
throw new
|
|
147
|
+
throw new HttpError(EHttpStatusCode.BadRequest, 'Could not read content-type: ' + line);
|
|
148
148
|
continue;
|
|
149
149
|
}
|
|
150
150
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/http-body",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "@wooksjs/http-body",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"url": "https://github.com/wooksjs/wooksjs/issues"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@wooksjs/event-http": "0.2.
|
|
34
|
+
"@wooksjs/event-http": "0.2.5"
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/http-body#readme"
|
|
37
37
|
}
|