source: frontend/node_modules/http-parser-js/http-parser.d.ts

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 4.5 KB
Line 
1type ParserType =
2 | 'REQUEST'
3 | 'RESPONSE'
4
5type 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
41type StateHeaderKey =
42 | 'REQUEST_LINE'
43 | 'RESPONSE_LINE'
44 | 'HEADER'
45
46type StateFinishAllowedKey =
47 | 'REQUEST_LINE'
48 | 'RESPONSE_LINE'
49 | 'BODY_RAW'
50
51type HeaderObject = Array<string>
52type noop<T = void> = ()=> T
53
54type 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}
65export 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
78export type OnBodyParser = (chunk: Buffer, offset: number, length: number)=> void
79// Only called in the slow case where slow means
80// that the request headers were either fragmented
81// across multiple TCP packets or too large to be
82// processed in a single run. This method is also
83// called to process trailing HTTP headers.
84export type OnHeadersParser = (headers: string[], url: string)=> void
85
86declare class HTTPParserJS {
87 initialize(type: ParserType, async_resource?: unknown): void
88
89 // Some handler stubs, needed for compatibility
90 [HTTPParser.kOnHeaders]: OnHeadersParser
91 [HTTPParser.kOnHeadersComplete]: OnHeadersCompleteParser
92 [HTTPParser.kOnBody]: OnBodyParser
93 [HTTPParser.kOnMessageComplete]: noop
94
95 /**
96 * Max number of bytes that will be parsed as headers, 80kb by default
97 * @default 81920
98 */
99 maxHeaderSize: number
100
101 reinitialize: HTTPParserConstructor
102 close: noop
103 pause: noop
104 resume: noop
105 free: noop
106 private _compatMode0_11: false | boolean
107 getAsyncId: noop<0>
108
109 execute(chunk: Buffer, start?: number, length?: number): number | Error
110 finish(): void | Error
111
112 // These three methods are used for an internal speed optimization, and it also
113 // works if theses are noops. Basically consume() asks us to read the bytes
114 // ourselves, but if we don't do it we get them through execute().
115 consume: noop
116 unconsume: noop
117 getCurrentBuffer: noop
118
119 /**
120 * For correct error handling - see HTTPParser#execute
121 * @example this.userCall()(userFunction('arg'));
122 */
123 userCall<T = unknown>(): (ret?: T)=> T
124 private nextRequest: noop
125 private consumeLine: noop<string|void>
126 parseHeader(line: string, headers: string[]): void
127 private REQUEST_LINE: noop
128 private RESPONSE_LINE: noop
129 shouldKeepAlive(): boolean
130 /**
131 * For older versions of node (v6.x and older?), that return `skipBody=1` or `skipBody=true`, need this `return true;` if it's an upgrade request.
132 */
133 private HEADER(): void | boolean
134 private BODY_CHUNKHEAD(): void
135 private BODY_CHUNK(): void
136 private BODY_CHUNKEMPTYLINE(): void
137 private BODY_CHUNKTRAILERS(): void
138 private BODY_RAW(): void
139 private BODY_SIZED(): void
140
141 get onHeaders(): OnHeadersParser
142 set onHeaders(to: OnHeadersParser)
143
144 get onHeadersComplete(): OnHeadersCompleteParser
145 set onHeadersComplete(to: OnHeadersCompleteParser)
146
147 get onBody(): OnBodyParser
148 set onBody(to: OnBodyParser)
149
150 get onMessageComplete(): noop
151 set onMessageComplete(to: noop)
152}
153
154interface HTTPParserConstructor extends Function {
155 new(type?: ParserType): HTTPParserJS
156 (type?: ParserType): void
157
158 readonly prototype: HTTPParserJS
159
160 readonly REQUEST: 'REQUEST'
161 readonly RESPONSE: 'RESPONSE'
162 readonly methods: RequestMethod[]
163
164 encoding: 'ascii'|string
165 /**
166 * maxHeaderSize (in bytes) is configurable, but 80kb by default;
167 * @default 80 * 1024 = 80kb
168 */
169 maxHeaderSize: 81920|number
170
171 // Note: *not* starting with kOnHeaders=0 line the Node parser, because any
172 // newly added constants (kOnTimeout in Node v12.19.0) will overwrite 0!
173 readonly kOnHeaders: 1
174 readonly kOnHeadersComplete: 2
175 readonly kOnBody: 3
176 readonly kOnMessageComplete: 4
177
178 kOnExecute(): void
179}
180export const HTTPParser: HTTPParserConstructor
181export const methods: RequestMethod[]
Note: See TracBrowser for help on using the repository browser.