1 | type ParserType =
|
2 | | 'REQUEST'
|
3 | | 'RESPONSE'
|
4 |
|
5 | type RequestMethod =
|
6 | | 'DELETE'
|
7 | | 'GET'
|
8 | | 'HEAD'
|
9 | | 'POST'
|
10 | | 'PUT'
|
11 | | 'CONNECT'
|
12 | | 'OPTIONS'
|
13 | | 'TRACE'
|
14 | | 'COPY'
|
15 | | 'LOCK'
|
16 | | 'MKCOL'
|
17 | | 'MOVE'
|
18 | | 'PROPFIND'
|
19 | | 'PROPPATCH'
|
20 | | 'SEARCH'
|
21 | | 'UNLOCK'
|
22 | | 'BIND'
|
23 | | 'REBIND'
|
24 | | 'UNBIND'
|
25 | | 'ACL'
|
26 | | 'REPORT'
|
27 | | 'MKACTIVITY'
|
28 | | 'CHECKOUT'
|
29 | | 'MERGE'
|
30 | | 'M-SEARCH'
|
31 | | 'NOTIFY'
|
32 | | 'SUBSCRIBE'
|
33 | | 'UNSUBSCRIBE'
|
34 | | 'PATCH'
|
35 | | 'PURGE'
|
36 | | 'MKCALENDAR'
|
37 | | 'LINK'
|
38 | | 'UNLINK'
|
39 | | string
|
40 |
|
41 | type StateHeaderKey =
|
42 | | 'REQUEST_LINE'
|
43 | | 'RESPONSE_LINE'
|
44 | | 'HEADER'
|
45 |
|
46 | type StateFinishAllowedKey =
|
47 | | 'REQUEST_LINE'
|
48 | | 'RESPONSE_LINE'
|
49 | | 'BODY_RAW'
|
50 |
|
51 | type HeaderObject = Array<string>
|
52 | type noop<T = void> = ()=> T
|
53 |
|
54 | type HeaderInfo<HEADER = HeaderObject> = {
|
55 | versionMajor: number
|
56 | versionMinor: number
|
57 | headers: HEADER
|
58 | method: number
|
59 | url: string
|
60 | statusCode: number
|
61 | statusMessage: string
|
62 | upgrade: boolean
|
63 | shouldKeepAlive: boolean
|
64 | }
|
65 | export type OnHeadersCompleteParser<HEADER = HeaderObject, Mode_0_12 extends boolean = true> = Mode_0_12 extends true
|
66 | ? (info: HeaderInfo<HEADER>)=> number | void
|
67 | : (
|
68 | versionMajor: number,
|
69 | versionMinor: number,
|
70 | headers: HEADER,
|
71 | method: number,
|
72 | url: string,
|
73 | statusCode: number,
|
74 | statusMessage: string,
|
75 | upgrade: boolean,
|
76 | shouldKeepAlive: boolean,
|
77 | )=> number | void
|
78 | export type OnBodyParser = (chunk: Buffer, offset: number, length: number)=> void
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | export type OnHeadersParser = (headers: string[], url: string)=> void
|
85 |
|
86 | declare class HTTPParserJS {
|
87 | initialize(type: ParserType, async_resource?: unknown): void
|
88 |
|
89 |
|
90 | [HTTPParser.kOnHeaders]: OnHeadersParser
|
91 | [HTTPParser.kOnHeadersComplete]: OnHeadersCompleteParser
|
92 | [HTTPParser.kOnBody]: OnBodyParser
|
93 | [HTTPParser.kOnMessageComplete]: noop
|
94 |
|
95 | reinitialize: HTTPParserConstructor
|
96 | close: noop
|
97 | pause: noop
|
98 | resume: noop
|
99 | free: noop
|
100 | private _compatMode0_11: false | boolean
|
101 | getAsyncId: noop<0>
|
102 |
|
103 | execute(chunk: Buffer, start?: number, length?: number): number | Error
|
104 | finish(): void | Error
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | consume: noop
|
110 | unconsume: noop
|
111 | getCurrentBuffer: noop
|
112 |
|
113 | |
114 |
|
115 |
|
116 |
|
117 | userCall<T = unknown>(): (ret?: T)=> T
|
118 | private nextRequest: noop
|
119 | private consumeLine: noop<string|void>
|
120 | parseHeader(line: string, headers: string[]): void
|
121 | private REQUEST_LINE: noop
|
122 | private RESPONSE_LINE: noop
|
123 | shouldKeepAlive(): boolean
|
124 | |
125 |
|
126 |
|
127 | private HEADER(): void | boolean
|
128 | private BODY_CHUNKHEAD(): void
|
129 | private BODY_CHUNK(): void
|
130 | private BODY_CHUNKEMPTYLINE(): void
|
131 | private BODY_CHUNKTRAILERS(): void
|
132 | private BODY_RAW(): void
|
133 | private BODY_SIZED(): void
|
134 |
|
135 | get onHeaders(): OnHeadersParser
|
136 | set onHeaders(to: OnHeadersParser)
|
137 |
|
138 | get onHeadersComplete(): OnHeadersCompleteParser
|
139 | set onHeadersComplete(to: OnHeadersCompleteParser)
|
140 |
|
141 | get onBody(): OnBodyParser
|
142 | set onBody(to: OnBodyParser)
|
143 |
|
144 | get onMessageComplete(): noop
|
145 | set onMessageComplete(to: noop)
|
146 | }
|
147 |
|
148 | interface HTTPParserConstructor extends Function {
|
149 | new(type?: ParserType): HTTPParserJS
|
150 | (type?: ParserType): void
|
151 |
|
152 | readonly prototype: HTTPParserJS
|
153 |
|
154 | readonly REQUEST: 'REQUEST'
|
155 | readonly RESPONSE: 'RESPONSE'
|
156 | readonly methods: RequestMethod[]
|
157 |
|
158 | encoding: 'ascii'|string
|
159 | |
160 |
|
161 |
|
162 |
|
163 | maxHeaderSize: 81920|number
|
164 |
|
165 |
|
166 |
|
167 | readonly kOnHeaders: 1
|
168 | readonly kOnHeadersComplete: 2
|
169 | readonly kOnBody: 3
|
170 | readonly kOnMessageComplete: 4
|
171 |
|
172 | kOnExecute(): void
|
173 | }
|
174 | export const HTTPParser: HTTPParserConstructor
|
175 | export const methods: RequestMethod[]
|