corecdtl 0.1.9 → 0.2.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/dist/http/chunker/ChunkProgression.d.ts +2 -1
- package/dist/http/chunker/ChunkProgression.js +4 -3
- package/dist/http/context/ApiContext.js +9 -4
- package/dist/http/context/HttpContext.js +2 -1
- package/dist/http/context/WebContext.d.ts +1 -1
- package/dist/http/factory/accumulator.js +1 -1
- package/dist/http.d.ts +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +3 -2
- package/prebuilds/darwin-arm64/corecdtl.node +0 -0
- package/prebuilds/linux-x64/corecdtl.node +0 -0
|
@@ -14,10 +14,11 @@ declare class ChunkProgression {
|
|
|
14
14
|
mainOffset: number;
|
|
15
15
|
retFlag: number;
|
|
16
16
|
rawBuf: Buffer;
|
|
17
|
+
writeOffset: number;
|
|
17
18
|
private respCpool;
|
|
18
19
|
private cPool;
|
|
19
20
|
private parseInitial;
|
|
20
|
-
constructor(cPool: any, parseInitial: Function, respCpool: any);
|
|
21
|
+
constructor(cPool: any, parseInitial: Function, respCpool: any, rawBufferSize: number);
|
|
21
22
|
allocateResp(): any;
|
|
22
23
|
reset(): void;
|
|
23
24
|
free(): void;
|
|
@@ -8,7 +8,7 @@ const FixedChunkedParser_1 = __importDefault(require("./FixedChunkedParser"));
|
|
|
8
8
|
const StreamingChunkedParser_1 = __importDefault(require("./StreamingChunkedParser"));
|
|
9
9
|
const UntilEndChunkerParser_1 = require("./UntilEndChunkerParser");
|
|
10
10
|
class ChunkProgression {
|
|
11
|
-
constructor(cPool, parseInitial, respCpool) {
|
|
11
|
+
constructor(cPool, parseInitial, respCpool, rawBufferSize) {
|
|
12
12
|
this.cPool = cPool;
|
|
13
13
|
this.fn = parseInitial;
|
|
14
14
|
this.chunkParser = {
|
|
@@ -24,8 +24,9 @@ class ChunkProgression {
|
|
|
24
24
|
this.method = http_1.Http.HttpMethod.GET;
|
|
25
25
|
this.headerSize = 0;
|
|
26
26
|
this.mainOffset = 0;
|
|
27
|
+
this.writeOffset = 0;
|
|
27
28
|
this.retFlag = http_1.Http.RetFlagBits.FLAG_OK;
|
|
28
|
-
this.rawBuf = Buffer.allocUnsafe(
|
|
29
|
+
this.rawBuf = Buffer.allocUnsafe(rawBufferSize);
|
|
29
30
|
this.objId = cPool.registerObj(this);
|
|
30
31
|
this.respCpool = respCpool;
|
|
31
32
|
this.parseInitial = parseInitial;
|
|
@@ -45,7 +46,7 @@ class ChunkProgression {
|
|
|
45
46
|
this.headerSize = 0;
|
|
46
47
|
this.mainOffset = 0;
|
|
47
48
|
this.retFlag = http_1.Http.RetFlagBits.FLAG_OK;
|
|
48
|
-
this.
|
|
49
|
+
this.writeOffset = 0;
|
|
49
50
|
}
|
|
50
51
|
free() {
|
|
51
52
|
this.reset();
|
|
@@ -63,7 +63,8 @@ class ApiContext extends HttpContext_1.default {
|
|
|
63
63
|
socket.destroy();
|
|
64
64
|
return;
|
|
65
65
|
case http_1.Http.RetFlagBits.FLAG_UNTERMINATED_HEADERS:
|
|
66
|
-
p.rawBuf
|
|
66
|
+
chunk.copy(p.rawBuf, 0);
|
|
67
|
+
p.writeOffset = chunk.length;
|
|
67
68
|
p.routePipe = this.routePipes[routeId];
|
|
68
69
|
p.fn = this.parseHeader;
|
|
69
70
|
return;
|
|
@@ -87,7 +88,8 @@ class ApiContext extends HttpContext_1.default {
|
|
|
87
88
|
return;
|
|
88
89
|
};
|
|
89
90
|
this.parseHeader = (socket, chunk, p) => {
|
|
90
|
-
|
|
91
|
+
chunk.copy(p.rawBuf, p.writeOffset);
|
|
92
|
+
p.writeOffset += chunk.length;
|
|
91
93
|
this.httpCore.scannerHeader(p.rawBuf, p, this.state.maxHeaderNameSize, this.state.maxHeaderValueSize, this.state.maxHeaderSize);
|
|
92
94
|
if (p.retFlag !== http_1.Http.RetFlagBits.FLAG_OK) {
|
|
93
95
|
switch (p.retFlag) {
|
|
@@ -118,14 +120,17 @@ class ApiContext extends HttpContext_1.default {
|
|
|
118
120
|
this.bindServer(opts?.netServerOptions);
|
|
119
121
|
}
|
|
120
122
|
bindServer(netServerOptions) {
|
|
121
|
-
this.server = new net_1.default.Server(
|
|
123
|
+
this.server = new net_1.default.Server({
|
|
124
|
+
...netServerOptions,
|
|
125
|
+
highWaterMark: 64 * 1024
|
|
126
|
+
}, (socket) => {
|
|
122
127
|
let p = this.chunkPool.allocate();
|
|
123
128
|
if (!p) {
|
|
124
129
|
socket.destroy();
|
|
125
130
|
return;
|
|
126
131
|
}
|
|
127
132
|
socket.setTimeout(this.state.timeout);
|
|
128
|
-
|
|
133
|
+
socket.setNoDelay(false);
|
|
129
134
|
// socket.setKeepAlive(true, 60000);
|
|
130
135
|
socket.on("data", chunk => {
|
|
131
136
|
p.fn(socket, chunk, p);
|
|
@@ -51,8 +51,9 @@ class HttpContext {
|
|
|
51
51
|
}
|
|
52
52
|
setRegisterChunkProgression(n, cPool, respCPool) {
|
|
53
53
|
const objs = [];
|
|
54
|
+
const rawBufferSize = this.state.maxHeaderSize + this.state.requestQuerySize + this.state.maxContentSize;
|
|
54
55
|
for (let i = 0; i < n; i++) {
|
|
55
|
-
const cpObj = new ChunkProgression_1.default(cPool, this.parseInitial, respCPool);
|
|
56
|
+
const cpObj = new ChunkProgression_1.default(cPool, this.parseInitial, respCPool, rawBufferSize);
|
|
56
57
|
if (this.bootstrapPoolChunkProgressionFn) {
|
|
57
58
|
this.bootstrapPoolChunkProgressionFn(cpObj);
|
|
58
59
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Http } from "../../http";
|
|
2
2
|
import HttpContext from "./HttpContext";
|
|
3
3
|
import net from "net";
|
|
4
|
-
type RouteDefinationFn = (socket: net.Socket, p: Http.ChunkProgression, routeId: number, chunk: Buffer
|
|
4
|
+
type RouteDefinationFn = (socket: net.Socket, p: Http.ChunkProgression, routeId: number, chunk: Buffer) => void;
|
|
5
5
|
declare class WebContext extends HttpContext {
|
|
6
6
|
protected contentDecoding: Http.ContentDecoding;
|
|
7
7
|
protected contentEncoding: Http.ContentEncoding;
|
|
@@ -153,7 +153,7 @@ function createAccumulators(ctx) {
|
|
|
153
153
|
if (already.length === p.contentLen) {
|
|
154
154
|
// socket.pause();
|
|
155
155
|
p.routePipe.pipeHandler(already, p, contentTypeParsers, contentDecoding, p.routePipe.mws, (ret) => {
|
|
156
|
-
socket.write(ret);
|
|
156
|
+
const writeRet = socket.write(ret);
|
|
157
157
|
if (h.connection == "close") {
|
|
158
158
|
socket.destroySoon();
|
|
159
159
|
}
|
package/dist/http.d.ts
CHANGED
|
@@ -668,6 +668,11 @@ export declare namespace Http {
|
|
|
668
668
|
* If the headers and body arrive in the same chunk, `rawBuf` will contain the body part as well until it is fully processed.
|
|
669
669
|
*/
|
|
670
670
|
rawBuf: Buffer;
|
|
671
|
+
/**
|
|
672
|
+
* @property {number} writeOffset
|
|
673
|
+
* @description The current write offset within `rawBuf` where the next incoming data chunk should be written.
|
|
674
|
+
*/
|
|
675
|
+
writeOffset: number;
|
|
671
676
|
/**
|
|
672
677
|
* @property {ChunkParser} chunkParser
|
|
673
678
|
* @description An internal object responsible for parsing chunked transfer encoding body data.
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ declare function createServer(opts?: Http.ServerOptions): {
|
|
|
7
7
|
};
|
|
8
8
|
export { createServer };
|
|
9
9
|
export * from "./http";
|
|
10
|
+
export * from "./http/response/PipeResponseBase";
|
|
10
11
|
export * as Factory from "./http/factory/factory";
|
|
11
12
|
export * as Pipeline from "./http/factory/pipeline";
|
|
12
13
|
export * as Accumulator from "./http/factory/accumulator";
|
package/dist/index.js
CHANGED
|
@@ -63,6 +63,7 @@ function createServer(opts) {
|
|
|
63
63
|
// Core types (main public API)
|
|
64
64
|
// ================================
|
|
65
65
|
__exportStar(require("./http"), exports);
|
|
66
|
+
__exportStar(require("./http/response/PipeResponseBase"), exports);
|
|
66
67
|
// ================================
|
|
67
68
|
// Factories / Builders
|
|
68
69
|
// ================================
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "corecdtl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "High-performance customizable HTTP engine",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"benchmark": "node benchmark/e2e/run.js",
|
|
27
27
|
"prepublishOnly": "npm run build",
|
|
28
28
|
"example": "node example/server.js",
|
|
29
|
-
"example:web": "node example/server.web.js"
|
|
29
|
+
"example:web": "node example/server.web.js",
|
|
30
|
+
"example:api": "node example/server.api.js"
|
|
30
31
|
},
|
|
31
32
|
"files": [
|
|
32
33
|
"dist",
|
|
Binary file
|
|
Binary file
|