@duplojs/http 0.8.4 → 0.8.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/core/request/bodyController/formData.cjs +1 -0
- package/dist/core/request/bodyController/formData.d.ts +2 -0
- package/dist/core/request/bodyController/formData.mjs +1 -0
- package/dist/interfaces/node/bodyReaders/formData/index.cjs +1 -0
- package/dist/interfaces/node/bodyReaders/formData/index.mjs +1 -0
- package/dist/interfaces/node/bodyReaders/formData/readRequestFormData.cjs +10 -1
- package/dist/interfaces/node/bodyReaders/formData/readRequestFormData.d.ts +2 -1
- package/dist/interfaces/node/bodyReaders/formData/readRequestFormData.mjs +10 -1
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ function controlBodyAsFormData(params) {
|
|
|
9
9
|
maxFileQuantity: params.maxFileQuantity,
|
|
10
10
|
bodyMaxSize: params.bodyMaxSize && utils.stringToBytes(params.bodyMaxSize),
|
|
11
11
|
fileMaxSize: params.fileMaxSize && utils.stringToBytes(params.fileMaxSize),
|
|
12
|
+
textFieldMaxSize: params.textFieldMaxSize && utils.stringToBytes(params.textFieldMaxSize),
|
|
12
13
|
mimeType: params.mimeType !== undefined
|
|
13
14
|
? utils.toRegExp(params.mimeType)
|
|
14
15
|
: undefined,
|
|
@@ -4,6 +4,7 @@ export interface FormDataBodyReaderParams extends BodyControllerParams {
|
|
|
4
4
|
maxFileQuantity: number;
|
|
5
5
|
mimeType?: RegExp;
|
|
6
6
|
fileMaxSize?: number;
|
|
7
|
+
textFieldMaxSize?: number;
|
|
7
8
|
maxBufferSize: number;
|
|
8
9
|
maxIndexArray: number;
|
|
9
10
|
maxKeyLength: number;
|
|
@@ -15,6 +16,7 @@ export interface ControlBodyAsFormDataParams {
|
|
|
15
16
|
mimeType?: string | AnyTuple<string> | RegExp;
|
|
16
17
|
bodyMaxSize?: number | BytesInString;
|
|
17
18
|
fileMaxSize?: number | BytesInString;
|
|
19
|
+
textFieldMaxSize?: number | BytesInString;
|
|
18
20
|
maxBufferSize?: number | BytesInString;
|
|
19
21
|
maxIndexArray?: number;
|
|
20
22
|
maxKeyLength?: number;
|
|
@@ -7,6 +7,7 @@ function controlBodyAsFormData(params) {
|
|
|
7
7
|
maxFileQuantity: params.maxFileQuantity,
|
|
8
8
|
bodyMaxSize: params.bodyMaxSize && stringToBytes(params.bodyMaxSize),
|
|
9
9
|
fileMaxSize: params.fileMaxSize && stringToBytes(params.fileMaxSize),
|
|
10
|
+
textFieldMaxSize: params.textFieldMaxSize && stringToBytes(params.textFieldMaxSize),
|
|
10
11
|
mimeType: params.mimeType !== undefined
|
|
11
12
|
? toRegExp(params.mimeType)
|
|
12
13
|
: undefined,
|
|
@@ -55,6 +55,7 @@ function createFormDataBodyReaderImplementation(serverParams) {
|
|
|
55
55
|
const result = await readRequestFormData.readRequestFormData(request.raw.request, new Map(), {
|
|
56
56
|
maxBodySize: params.bodyMaxSize ?? serverMaxBodySize,
|
|
57
57
|
fileMaxSize: params.fileMaxSize ?? Infinity,
|
|
58
|
+
textFieldMaxSize: params.textFieldMaxSize ?? Infinity,
|
|
58
59
|
maxFileQuantity: params.maxFileQuantity,
|
|
59
60
|
mimeType: params.mimeType,
|
|
60
61
|
maxBufferSize: params.maxBufferSize,
|
|
@@ -53,6 +53,7 @@ function createFormDataBodyReaderImplementation(serverParams) {
|
|
|
53
53
|
const result = await readRequestFormData(request.raw.request, new Map(), {
|
|
54
54
|
maxBodySize: params.bodyMaxSize ?? serverMaxBodySize,
|
|
55
55
|
fileMaxSize: params.fileMaxSize ?? Infinity,
|
|
56
|
+
textFieldMaxSize: params.textFieldMaxSize ?? Infinity,
|
|
56
57
|
maxFileQuantity: params.maxFileQuantity,
|
|
57
58
|
mimeType: params.mimeType,
|
|
58
59
|
maxBufferSize: params.maxBufferSize,
|
|
@@ -32,6 +32,7 @@ async function readRequestFormData(request, firstValueAccumulator, params, onRec
|
|
|
32
32
|
let currentStream = undefined;
|
|
33
33
|
let fileQuantity = 0;
|
|
34
34
|
let currentFileSize = undefined;
|
|
35
|
+
let currentTextFieldSize = undefined;
|
|
35
36
|
const checkSize = (receivedChunk) => {
|
|
36
37
|
size += receivedChunk.length;
|
|
37
38
|
return size > params.maxBodySize
|
|
@@ -61,6 +62,7 @@ async function readRequestFormData(request, firstValueAccumulator, params, onRec
|
|
|
61
62
|
}
|
|
62
63
|
if (header.filename !== undefined) {
|
|
63
64
|
currentFileSize = 0;
|
|
65
|
+
currentTextFieldSize = undefined;
|
|
64
66
|
fileQuantity++;
|
|
65
67
|
if (fileQuantity > params.maxFileQuantity) {
|
|
66
68
|
return new error.BodyParseFormDataError("File quantity exceeds limit.");
|
|
@@ -72,6 +74,7 @@ async function readRequestFormData(request, firstValueAccumulator, params, onRec
|
|
|
72
74
|
}
|
|
73
75
|
else {
|
|
74
76
|
currentFileSize = undefined;
|
|
77
|
+
currentTextFieldSize = 0;
|
|
75
78
|
}
|
|
76
79
|
const newStream = await onReceiveHeader(header);
|
|
77
80
|
if (newStream instanceof Error) {
|
|
@@ -93,10 +96,16 @@ async function readRequestFormData(request, firstValueAccumulator, params, onRec
|
|
|
93
96
|
}
|
|
94
97
|
if (typeof currentFileSize === "number") {
|
|
95
98
|
currentFileSize += chunk.length;
|
|
96
|
-
if (
|
|
99
|
+
if (currentFileSize > params.fileMaxSize) {
|
|
97
100
|
return new error.BodyParseFormDataError("File size exceeds limit.");
|
|
98
101
|
}
|
|
99
102
|
}
|
|
103
|
+
if (typeof currentTextFieldSize === "number") {
|
|
104
|
+
currentTextFieldSize += chunk.length;
|
|
105
|
+
if (currentTextFieldSize > params.textFieldMaxSize) {
|
|
106
|
+
return new error.BodyParseFormDataError("Text field size exceeds limit.");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
100
109
|
await currentStream.onReceiveChunk(chunk);
|
|
101
110
|
return true;
|
|
102
111
|
};
|
|
@@ -14,7 +14,8 @@ export interface ReadRequestFormDataParams {
|
|
|
14
14
|
maxFileQuantity: number;
|
|
15
15
|
maxBufferSize: number;
|
|
16
16
|
maxKeyLength: number;
|
|
17
|
-
fileMaxSize
|
|
17
|
+
fileMaxSize: number;
|
|
18
|
+
textFieldMaxSize: number;
|
|
18
19
|
mimeType?: RegExp;
|
|
19
20
|
}
|
|
20
21
|
export declare function readRequestFormData<GenericValueAccumulator extends unknown, GenericOutputHeader extends E.Left = never>(request: http.IncomingMessage, firstValueAccumulator: GenericValueAccumulator, params: ReadRequestFormDataParams, onReceiveHeader: (header: HeaderPartInformation) => MaybePromise<ReadRequestFormDataStreamChunkEvent<GenericValueAccumulator> | Error>): Promise<E.Left<"server-error", unknown> | GenericOutputHeader | E.Error<Error> | GenericValueAccumulator>;
|
|
@@ -30,6 +30,7 @@ async function readRequestFormData(request, firstValueAccumulator, params, onRec
|
|
|
30
30
|
let currentStream = undefined;
|
|
31
31
|
let fileQuantity = 0;
|
|
32
32
|
let currentFileSize = undefined;
|
|
33
|
+
let currentTextFieldSize = undefined;
|
|
33
34
|
const checkSize = (receivedChunk) => {
|
|
34
35
|
size += receivedChunk.length;
|
|
35
36
|
return size > params.maxBodySize
|
|
@@ -59,6 +60,7 @@ async function readRequestFormData(request, firstValueAccumulator, params, onRec
|
|
|
59
60
|
}
|
|
60
61
|
if (header.filename !== undefined) {
|
|
61
62
|
currentFileSize = 0;
|
|
63
|
+
currentTextFieldSize = undefined;
|
|
62
64
|
fileQuantity++;
|
|
63
65
|
if (fileQuantity > params.maxFileQuantity) {
|
|
64
66
|
return new BodyParseFormDataError("File quantity exceeds limit.");
|
|
@@ -70,6 +72,7 @@ async function readRequestFormData(request, firstValueAccumulator, params, onRec
|
|
|
70
72
|
}
|
|
71
73
|
else {
|
|
72
74
|
currentFileSize = undefined;
|
|
75
|
+
currentTextFieldSize = 0;
|
|
73
76
|
}
|
|
74
77
|
const newStream = await onReceiveHeader(header);
|
|
75
78
|
if (newStream instanceof Error) {
|
|
@@ -91,10 +94,16 @@ async function readRequestFormData(request, firstValueAccumulator, params, onRec
|
|
|
91
94
|
}
|
|
92
95
|
if (typeof currentFileSize === "number") {
|
|
93
96
|
currentFileSize += chunk.length;
|
|
94
|
-
if (
|
|
97
|
+
if (currentFileSize > params.fileMaxSize) {
|
|
95
98
|
return new BodyParseFormDataError("File size exceeds limit.");
|
|
96
99
|
}
|
|
97
100
|
}
|
|
101
|
+
if (typeof currentTextFieldSize === "number") {
|
|
102
|
+
currentTextFieldSize += chunk.length;
|
|
103
|
+
if (currentTextFieldSize > params.textFieldMaxSize) {
|
|
104
|
+
return new BodyParseFormDataError("Text field size exceeds limit.");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
98
107
|
await currentStream.onReceiveChunk(chunk);
|
|
99
108
|
return true;
|
|
100
109
|
};
|