typenative 0.6.0 → 0.6.2
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/CHANGELOG.md +93 -0
- package/README.md +2 -1
- package/bin/node/core.js +5 -0
- package/bin/node/events.js +139 -5
- package/bin/node/http.js +1265 -127
- package/bin/node/stream.js +56 -7
- package/bin/node/stream_web.js +2 -2
- package/bin/node/url.js +27 -2
- package/bin/regex_vm.js +50 -2
- package/bin/transpiler.js +1365 -184
- package/bin/version.js +1 -1
- package/examples/README.md +28 -29
- package/examples/angular-templates/README.md +22 -20
- package/examples/json-server/README.md +16 -13
- package/examples/marked-cli/README.md +37 -22
- package/examples/marked-cli/main.ts +122 -4
- package/examples/react-compiler/README.md +56 -41
- package/examples/react-compiler/main.ts +173 -7
- package/examples/react-compiler/run-node.mjs +2 -0
- package/examples/yaml-cli/README.md +36 -30
- package/examples/yaml-cli/main.ts +236 -14
- package/package.json +1 -1
- package/performance/README.md +1 -0
- package/tsparser/go.mod +1 -1
- package/tsparser/go.sum +2 -2
package/bin/node/http.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// Client: http.request returns a ClientRequest (a Writable); the request goes
|
|
8
8
|
// out on the first write or on end(), the response is an IncomingMessage.
|
|
9
9
|
// Like Node: no redirects are followed and bodies are not decompressed.
|
|
10
|
-
import { defineClass, defineHelper, defineModule, setResults } from './registry.js';
|
|
10
|
+
import { defineClass, defineHelper, defineModule, setResults, isStringNode, isObjectLiteral, goString } from './registry.js';
|
|
11
11
|
import { STREAM_METHODS, STREAM_GETTERS, streamListenerTypes } from './stream.js';
|
|
12
12
|
import { SERVER_METHODS } from './net.js';
|
|
13
13
|
const httpHelper = `// node:http
|
|
@@ -127,79 +127,133 @@ func tnHeaderStrings(v interface{}) []string {
|
|
|
127
127
|
return []string{TnJSString(v)}
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
func tnLowerASCII(s string) string {
|
|
131
|
+
if s == "Content-Length" {
|
|
132
|
+
return "content-length"
|
|
133
|
+
}
|
|
134
|
+
if s == "Content-Type" {
|
|
135
|
+
return "content-type"
|
|
136
|
+
}
|
|
137
|
+
for i := 0; i < len(s); i++ {
|
|
138
|
+
c := s[i]
|
|
139
|
+
if (c >= 'A' && c <= 'Z') || c >= 0x80 {
|
|
140
|
+
return strings.ToLower(s)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return s
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
type tnHeaderEntry struct {
|
|
147
|
+
key string
|
|
148
|
+
name string
|
|
149
|
+
value interface{}
|
|
135
150
|
}
|
|
136
151
|
|
|
137
|
-
|
|
138
|
-
|
|
152
|
+
// Outgoing headers: case-insensitive, keeping the first spelling and the order
|
|
153
|
+
type tnHeaderStore struct {
|
|
154
|
+
entries []tnHeaderEntry
|
|
155
|
+
buf [4]tnHeaderEntry
|
|
139
156
|
}
|
|
140
157
|
|
|
141
158
|
func (h *tnHeaderStore) set(name string, value interface{}) {
|
|
142
|
-
key :=
|
|
143
|
-
|
|
144
|
-
h.
|
|
145
|
-
|
|
159
|
+
key := tnLowerASCII(name)
|
|
160
|
+
for i := range h.entries {
|
|
161
|
+
if h.entries[i].key == key {
|
|
162
|
+
h.entries[i].value = value
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if h.entries == nil {
|
|
167
|
+
h.entries = h.buf[:0]
|
|
146
168
|
}
|
|
147
|
-
h.
|
|
169
|
+
h.entries = append(h.entries, tnHeaderEntry{key: key, name: name, value: value})
|
|
148
170
|
}
|
|
149
171
|
|
|
150
|
-
func (h *tnHeaderStore) get(name string) interface{} {
|
|
172
|
+
func (h *tnHeaderStore) get(name string) interface{} {
|
|
173
|
+
key := tnLowerASCII(name)
|
|
174
|
+
for i := range h.entries {
|
|
175
|
+
if h.entries[i].key == key {
|
|
176
|
+
return h.entries[i].value
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return nil
|
|
180
|
+
}
|
|
151
181
|
|
|
152
182
|
func (h *tnHeaderStore) has(name string) bool {
|
|
153
|
-
|
|
154
|
-
|
|
183
|
+
key := tnLowerASCII(name)
|
|
184
|
+
for i := range h.entries {
|
|
185
|
+
if h.entries[i].key == key {
|
|
186
|
+
return true
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return false
|
|
155
190
|
}
|
|
156
191
|
|
|
157
192
|
func (h *tnHeaderStore) remove(name string) {
|
|
158
|
-
key :=
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
delete(h.names, key)
|
|
164
|
-
for i, k := range h.order {
|
|
165
|
-
if k == key {
|
|
166
|
-
h.order = append(h.order[:i], h.order[i+1:]...)
|
|
167
|
-
break
|
|
193
|
+
key := tnLowerASCII(name)
|
|
194
|
+
for i := range h.entries {
|
|
195
|
+
if h.entries[i].key == key {
|
|
196
|
+
h.entries = append(h.entries[:i], h.entries[i+1:]...)
|
|
197
|
+
return
|
|
168
198
|
}
|
|
169
199
|
}
|
|
170
200
|
}
|
|
171
201
|
|
|
172
202
|
func (h *tnHeaderStore) record() *TnMap[string, interface{}] {
|
|
173
203
|
m := TnNewMap[string, interface{}]()
|
|
174
|
-
for
|
|
175
|
-
m.Set(
|
|
204
|
+
for i := range h.entries {
|
|
205
|
+
m.Set(h.entries[i].key, h.entries[i].value)
|
|
176
206
|
}
|
|
177
207
|
return m
|
|
178
208
|
}
|
|
179
209
|
|
|
180
210
|
func (h *tnHeaderStore) keys() []string {
|
|
181
|
-
|
|
211
|
+
out := make([]string, len(h.entries))
|
|
212
|
+
for i := range h.entries {
|
|
213
|
+
out[i] = h.entries[i].key
|
|
214
|
+
}
|
|
215
|
+
return out
|
|
182
216
|
}
|
|
183
217
|
|
|
184
218
|
func (h *tnHeaderStore) rawNames() []string {
|
|
185
|
-
out := []string
|
|
186
|
-
for
|
|
187
|
-
out =
|
|
219
|
+
out := make([]string, len(h.entries))
|
|
220
|
+
for i := range h.entries {
|
|
221
|
+
out[i] = h.entries[i].name
|
|
188
222
|
}
|
|
189
223
|
return out
|
|
190
224
|
}
|
|
191
225
|
|
|
192
226
|
func (h *tnHeaderStore) toGo(dst http.Header) {
|
|
193
|
-
for
|
|
194
|
-
name := h.
|
|
227
|
+
for i := range h.entries {
|
|
228
|
+
name := h.entries[i].name
|
|
229
|
+
canon := http.CanonicalHeaderKey(name)
|
|
195
230
|
dst.Del(name)
|
|
196
|
-
for _, v := range tnHeaderStrings(h.
|
|
197
|
-
dst[
|
|
231
|
+
for _, v := range tnHeaderStrings(h.entries[i].value) {
|
|
232
|
+
dst[canon] = append(dst[canon], v)
|
|
198
233
|
}
|
|
199
234
|
}
|
|
200
235
|
}
|
|
201
236
|
|
|
202
237
|
func (h *tnHeaderStore) setAll(headers interface{}) {
|
|
238
|
+
if headers == nil {
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
switch m := headers.(type) {
|
|
242
|
+
case *TnMap[string, string]:
|
|
243
|
+
if m != nil {
|
|
244
|
+
for k, v := range m.All() {
|
|
245
|
+
h.set(k, v)
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return
|
|
249
|
+
case *TnMap[string, interface{}]:
|
|
250
|
+
if m != nil {
|
|
251
|
+
for k, v := range m.All() {
|
|
252
|
+
h.set(k, v)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return
|
|
256
|
+
}
|
|
203
257
|
for _, e := range tnEntries(headers) {
|
|
204
258
|
h.set(fmt.Sprint(e[0]), e[1])
|
|
205
259
|
}
|
|
@@ -213,42 +267,145 @@ type TnIncomingMessage struct {
|
|
|
213
267
|
httpVersion string
|
|
214
268
|
httpVersionMajor float64
|
|
215
269
|
httpVersionMinor float64
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
270
|
+
hdrs *TnMap[string, string]
|
|
271
|
+
hdrsDistinct *TnMap[string, []string]
|
|
272
|
+
rawHdrs []string
|
|
273
|
+
trlrs *TnMap[string, string]
|
|
220
274
|
statusCode float64
|
|
221
275
|
statusMessage string
|
|
222
276
|
complete bool
|
|
223
277
|
aborted bool
|
|
224
278
|
socket *TnSocket
|
|
279
|
+
rawGoHeader http.Header
|
|
280
|
+
rawHost string
|
|
281
|
+
rawChunked bool
|
|
282
|
+
rawH2 bool
|
|
283
|
+
rawTLS bool
|
|
284
|
+
rawHeaderBlock []byte
|
|
285
|
+
rawLocal net.Addr
|
|
286
|
+
rawRemote string
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
func (m *TnIncomingMessage) ensureSocket() *TnSocket {
|
|
290
|
+
if m.socket == nil && (m.rawLocal != nil || m.rawRemote != "") {
|
|
291
|
+
m.socket = tnInfoSocket(m.rawLocal, m.rawRemote)
|
|
292
|
+
if m.rawTLS {
|
|
293
|
+
m.socket.encrypted = true
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return m.socket
|
|
225
297
|
}
|
|
226
298
|
|
|
227
|
-
func (m *TnIncomingMessage) Get_socket() *TnSocket { return m.
|
|
228
|
-
func (m *TnIncomingMessage) Get_connection() *TnSocket { return m.
|
|
299
|
+
func (m *TnIncomingMessage) Get_socket() *TnSocket { return m.ensureSocket() }
|
|
300
|
+
func (m *TnIncomingMessage) Get_connection() *TnSocket { return m.ensureSocket() }
|
|
229
301
|
func (m *TnIncomingMessage) setTimeout(ms float64, cb ...interface{}) *TnIncomingMessage {
|
|
230
|
-
if m.
|
|
231
|
-
|
|
302
|
+
if s := m.ensureSocket(); s != nil {
|
|
303
|
+
s.setTimeout(ms, cb...)
|
|
232
304
|
}
|
|
233
305
|
return m
|
|
234
306
|
}
|
|
235
307
|
|
|
308
|
+
func (m *TnIncomingMessage) ensureHeaders() {
|
|
309
|
+
if m.hdrs != nil {
|
|
310
|
+
return
|
|
311
|
+
}
|
|
312
|
+
if len(m.rawHeaderBlock) > 0 {
|
|
313
|
+
tnIncomingHeadersRaw(m, m.rawHeaderBlock)
|
|
314
|
+
return
|
|
315
|
+
}
|
|
316
|
+
tnBuildIncomingHeaders(m, m.rawGoHeader, m.rawHost, m.rawChunked)
|
|
317
|
+
if m.rawH2 {
|
|
318
|
+
tnPseudoHeaders(m)
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
func (m *TnIncomingMessage) Get_headers() *TnMap[string, string] {
|
|
323
|
+
m.ensureHeaders()
|
|
324
|
+
return m.hdrs
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
func (m *TnIncomingMessage) Get_headersDistinct() *TnMap[string, []string] {
|
|
328
|
+
m.ensureHeaders()
|
|
329
|
+
return m.hdrsDistinct
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
func (m *TnIncomingMessage) Get_rawHeaders() []string {
|
|
333
|
+
m.ensureHeaders()
|
|
334
|
+
return m.rawHdrs
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
func (m *TnIncomingMessage) Get_trailers() *TnMap[string, string] {
|
|
338
|
+
if m.trlrs == nil {
|
|
339
|
+
m.trlrs = TnNewMap[string, string]()
|
|
340
|
+
}
|
|
341
|
+
return m.trlrs
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
func tnIncomingHeadersRaw(m *TnIncomingMessage, raw []byte) {
|
|
345
|
+
m.hdrs = TnNewMap[string, string]()
|
|
346
|
+
m.hdrsDistinct = TnNewMap[string, []string]()
|
|
347
|
+
m.rawHdrs = []string{}
|
|
348
|
+
rest := raw
|
|
349
|
+
for len(rest) > 0 {
|
|
350
|
+
idx := bytes.IndexByte(rest, '\\n')
|
|
351
|
+
var line []byte
|
|
352
|
+
if idx < 0 {
|
|
353
|
+
line = rest
|
|
354
|
+
rest = nil
|
|
355
|
+
} else {
|
|
356
|
+
line = rest[:idx]
|
|
357
|
+
rest = rest[idx+1:]
|
|
358
|
+
}
|
|
359
|
+
if len(line) > 0 && line[len(line)-1] == '\\r' {
|
|
360
|
+
line = line[:len(line)-1]
|
|
361
|
+
}
|
|
362
|
+
if len(line) == 0 {
|
|
363
|
+
break
|
|
364
|
+
}
|
|
365
|
+
colon := bytes.IndexByte(line, ':')
|
|
366
|
+
if colon <= 0 {
|
|
367
|
+
continue
|
|
368
|
+
}
|
|
369
|
+
name := string(bytes.TrimSpace(line[:colon]))
|
|
370
|
+
val := string(bytes.TrimSpace(line[colon+1:]))
|
|
371
|
+
key := tnLowerASCII(name)
|
|
372
|
+
m.rawHdrs = append(m.rawHdrs, name, val)
|
|
373
|
+
if existing, ok := m.hdrsDistinct.Lookup(key); ok {
|
|
374
|
+
m.hdrsDistinct.Set(key, append(existing, val))
|
|
375
|
+
sep := ", "
|
|
376
|
+
if key == "cookie" {
|
|
377
|
+
sep = "; "
|
|
378
|
+
}
|
|
379
|
+
m.hdrs.Set(key, m.hdrs.Get(key)+sep+val)
|
|
380
|
+
} else {
|
|
381
|
+
m.hdrsDistinct.Set(key, []string{val})
|
|
382
|
+
m.hdrs.Set(key, val)
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
236
387
|
// Headers as Node shows them: lower-case names, repeated values joined
|
|
237
388
|
func tnIncomingHeaders(m *TnIncomingMessage, h http.Header, host string, chunked bool) {
|
|
238
|
-
m.
|
|
239
|
-
m.
|
|
240
|
-
m.
|
|
389
|
+
m.rawGoHeader = h
|
|
390
|
+
m.rawHost = host
|
|
391
|
+
m.rawChunked = chunked
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
func tnBuildIncomingHeaders(m *TnIncomingMessage, h http.Header, host string, chunked bool) {
|
|
395
|
+
m.hdrs = TnNewMap[string, string]()
|
|
396
|
+
m.hdrsDistinct = TnNewMap[string, []string]()
|
|
397
|
+
m.rawHdrs = []string{}
|
|
241
398
|
add := func(name string, values []string) {
|
|
242
|
-
key :=
|
|
399
|
+
key := tnLowerASCII(name)
|
|
243
400
|
for _, v := range values {
|
|
244
|
-
m.
|
|
401
|
+
m.rawHdrs = append(m.rawHdrs, name, v)
|
|
245
402
|
}
|
|
246
|
-
m.
|
|
403
|
+
m.hdrsDistinct.Set(key, append([]string{}, values...))
|
|
247
404
|
sep := ", "
|
|
248
405
|
if key == "cookie" {
|
|
249
406
|
sep = "; "
|
|
250
407
|
}
|
|
251
|
-
m.
|
|
408
|
+
m.hdrs.Set(key, strings.Join(values, sep))
|
|
252
409
|
}
|
|
253
410
|
if host != "" {
|
|
254
411
|
add("Host", []string{host})
|
|
@@ -261,16 +418,18 @@ func tnIncomingHeaders(m *TnIncomingMessage, h http.Header, host string, chunked
|
|
|
261
418
|
for _, name := range names {
|
|
262
419
|
add(name, h[name])
|
|
263
420
|
}
|
|
264
|
-
if chunked && !m.
|
|
421
|
+
if chunked && !m.hdrs.Has("transfer-encoding") {
|
|
265
422
|
add("Transfer-Encoding", []string{"chunked"})
|
|
266
423
|
}
|
|
267
424
|
}
|
|
268
425
|
|
|
269
426
|
func tnNewIncoming() *TnIncomingMessage {
|
|
270
427
|
m := &TnIncomingMessage{}
|
|
271
|
-
m.
|
|
428
|
+
m.flowing = -1
|
|
429
|
+
m.decodeStrings = true
|
|
430
|
+
m.readableSide = true
|
|
431
|
+
m.asyncCtx = TnAsyncSnapshot()
|
|
272
432
|
m.tnSelf = m
|
|
273
|
-
m.trailers = TnNewMap[string, string]()
|
|
274
433
|
return m
|
|
275
434
|
}
|
|
276
435
|
|
|
@@ -341,14 +500,15 @@ func tnInfoSocket(local net.Addr, remote string) *TnSocket {
|
|
|
341
500
|
|
|
342
501
|
// One operation of a response, applied by the handler goroutine
|
|
343
502
|
type tnResOp struct {
|
|
344
|
-
status
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
503
|
+
status int
|
|
504
|
+
statusMsg string
|
|
505
|
+
header http.Header
|
|
506
|
+
trailer http.Header
|
|
507
|
+
data []byte
|
|
508
|
+
end bool
|
|
349
509
|
// Header ops: send the headers now (flushHeaders) instead of with the body
|
|
350
|
-
flush
|
|
351
|
-
done
|
|
510
|
+
flush bool
|
|
511
|
+
done func(err error)
|
|
352
512
|
}
|
|
353
513
|
|
|
354
514
|
// http.ServerResponse
|
|
@@ -358,8 +518,12 @@ type TnServerResponse struct {
|
|
|
358
518
|
statusMessage string
|
|
359
519
|
sendDate bool
|
|
360
520
|
headersSent bool
|
|
521
|
+
wroteHead bool
|
|
361
522
|
wroteData bool
|
|
362
|
-
|
|
523
|
+
inSyncTurn bool
|
|
524
|
+
fastEnd bool
|
|
525
|
+
fastBody []byte
|
|
526
|
+
store tnHeaderStore
|
|
363
527
|
req *TnIncomingMessage
|
|
364
528
|
mu sync.Mutex
|
|
365
529
|
ops []tnResOp
|
|
@@ -370,9 +534,19 @@ type TnServerResponse struct {
|
|
|
370
534
|
endPosted bool
|
|
371
535
|
}
|
|
372
536
|
|
|
373
|
-
func (res *TnServerResponse) Get_headersSent() bool { return res.headersSent }
|
|
537
|
+
func (res *TnServerResponse) Get_headersSent() bool { return res.headersSent || res.wroteHead }
|
|
374
538
|
func (res *TnServerResponse) Get_req() *TnIncomingMessage { return res.req }
|
|
375
|
-
func (res *TnServerResponse) Get_socket() *TnSocket { return res.req.
|
|
539
|
+
func (res *TnServerResponse) Get_socket() *TnSocket { return res.req.Get_socket() }
|
|
540
|
+
|
|
541
|
+
func (res *TnServerResponse) sig() chan struct{} {
|
|
542
|
+
res.mu.Lock()
|
|
543
|
+
if res.signal == nil {
|
|
544
|
+
res.signal = make(chan struct{}, 1)
|
|
545
|
+
}
|
|
546
|
+
ch := res.signal
|
|
547
|
+
res.mu.Unlock()
|
|
548
|
+
return ch
|
|
549
|
+
}
|
|
376
550
|
|
|
377
551
|
// Queues an op without waking the handler goroutine (it goes out with the next post)
|
|
378
552
|
func (res *TnServerResponse) queue(op tnResOp) {
|
|
@@ -382,9 +556,15 @@ func (res *TnServerResponse) queue(op tnResOp) {
|
|
|
382
556
|
}
|
|
383
557
|
|
|
384
558
|
func (res *TnServerResponse) post(op tnResOp) {
|
|
385
|
-
res.
|
|
559
|
+
res.mu.Lock()
|
|
560
|
+
res.ops = append(res.ops, op)
|
|
561
|
+
if res.signal == nil {
|
|
562
|
+
res.signal = make(chan struct{}, 1)
|
|
563
|
+
}
|
|
564
|
+
ch := res.signal
|
|
565
|
+
res.mu.Unlock()
|
|
386
566
|
select {
|
|
387
|
-
case
|
|
567
|
+
case ch <- struct{}{}:
|
|
388
568
|
default:
|
|
389
569
|
}
|
|
390
570
|
}
|
|
@@ -404,11 +584,12 @@ func (res *TnServerResponse) headerOp() tnResOp {
|
|
|
404
584
|
h["Date"] = nil
|
|
405
585
|
}
|
|
406
586
|
res.headersSent = true
|
|
407
|
-
|
|
587
|
+
res.wroteHead = true
|
|
588
|
+
return tnResOp{status: int(res.statusCode), statusMsg: res.statusMessage, header: h}
|
|
408
589
|
}
|
|
409
590
|
|
|
410
591
|
func (res *TnServerResponse) setHeader(name string, value interface{}) *TnServerResponse {
|
|
411
|
-
if res.headersSent {
|
|
592
|
+
if res.headersSent || res.wroteHead {
|
|
412
593
|
panic(TnNodeError("Error", "ERR_HTTP_HEADERS_SENT", "Cannot set headers after they are sent to the client"))
|
|
413
594
|
}
|
|
414
595
|
res.store.set(name, value)
|
|
@@ -416,9 +597,10 @@ func (res *TnServerResponse) setHeader(name string, value interface{}) *TnServer
|
|
|
416
597
|
}
|
|
417
598
|
|
|
418
599
|
func (res *TnServerResponse) setHeaders(headers interface{}) *TnServerResponse {
|
|
419
|
-
|
|
420
|
-
|
|
600
|
+
if res.headersSent || res.wroteHead {
|
|
601
|
+
panic(TnNodeError("Error", "ERR_HTTP_HEADERS_SENT", "Cannot set headers after they are sent to the client"))
|
|
421
602
|
}
|
|
603
|
+
res.store.setAll(headers)
|
|
422
604
|
return res
|
|
423
605
|
}
|
|
424
606
|
|
|
@@ -447,9 +629,19 @@ func (res *TnServerResponse) getHeaderNames() []string { return res.store.keys()
|
|
|
447
629
|
func (res *TnServerResponse) hasHeader(name string) bool { return res.store.has(name) }
|
|
448
630
|
func (res *TnServerResponse) removeHeader(name string) { res.store.remove(name) }
|
|
449
631
|
|
|
632
|
+
func (res *TnServerResponse) writeHeadKV(status float64, k string, v string) *TnServerResponse {
|
|
633
|
+
if res.headersSent || res.wroteHead {
|
|
634
|
+
panic(TnNodeError("Error", "ERR_HTTP_HEADERS_SENT", "Cannot write headers after they are sent to the client"))
|
|
635
|
+
}
|
|
636
|
+
res.statusCode = status
|
|
637
|
+
res.store.set(k, v)
|
|
638
|
+
res.wroteHead = true
|
|
639
|
+
return res
|
|
640
|
+
}
|
|
641
|
+
|
|
450
642
|
// writeHead(status, [statusMessage], [headers])
|
|
451
643
|
func (res *TnServerResponse) writeHead(status float64, args ...interface{}) *TnServerResponse {
|
|
452
|
-
if res.headersSent {
|
|
644
|
+
if res.headersSent || res.wroteHead {
|
|
453
645
|
panic(TnNodeError("Error", "ERR_HTTP_HEADERS_SENT", "Cannot write headers after they are sent to the client"))
|
|
454
646
|
}
|
|
455
647
|
res.statusCode = status
|
|
@@ -457,13 +649,10 @@ func (res *TnServerResponse) writeHead(status float64, args ...interface{}) *TnS
|
|
|
457
649
|
if s, ok := a.(string); ok {
|
|
458
650
|
res.statusMessage = s
|
|
459
651
|
} else if a != nil {
|
|
460
|
-
|
|
461
|
-
res.store.set(fmt.Sprint(e[0]), e[1])
|
|
462
|
-
}
|
|
652
|
+
res.store.setAll(a)
|
|
463
653
|
}
|
|
464
654
|
}
|
|
465
|
-
|
|
466
|
-
res.queue(res.headerOp())
|
|
655
|
+
res.wroteHead = true
|
|
467
656
|
return res
|
|
468
657
|
}
|
|
469
658
|
|
|
@@ -479,7 +668,40 @@ func (res *TnServerResponse) writeContinue() {}
|
|
|
479
668
|
|
|
480
669
|
// end(data?): a body written in one piece gets a Content-Length, as in Node
|
|
481
670
|
func (res *TnServerResponse) end(args ...interface{}) *TnServerResponse {
|
|
482
|
-
|
|
671
|
+
// writeHead() only records the status and headers (headersSent stays false),
|
|
672
|
+
// so the whole response can still be built on the connection goroutine.
|
|
673
|
+
if res.inSyncTurn && !res.headersSent && !res.wroteData && !res.writeEnded && !res.destroyed &&
|
|
674
|
+
len(res.ops) == 0 && len(res.writeQueue) == 0 && res.trailer == nil &&
|
|
675
|
+
res.state == nil && res.fn0 == nil && res.fn1 == nil && len(args) <= 1 {
|
|
676
|
+
if len(args) == 0 || args[0] == nil {
|
|
677
|
+
res.fastEnd = true
|
|
678
|
+
res.wroteHead = true
|
|
679
|
+
res.writeEnded = true
|
|
680
|
+
res.finished = true
|
|
681
|
+
res.closed = true
|
|
682
|
+
return res
|
|
683
|
+
}
|
|
684
|
+
switch d := args[0].(type) {
|
|
685
|
+
case string:
|
|
686
|
+
res.fastBody = unsafe.Slice(unsafe.StringData(d), len(d))
|
|
687
|
+
res.fastEnd = true
|
|
688
|
+
res.wroteHead = true
|
|
689
|
+
res.writeEnded = true
|
|
690
|
+
res.finished = true
|
|
691
|
+
res.closed = true
|
|
692
|
+
return res
|
|
693
|
+
case []byte:
|
|
694
|
+
res.fastBody = d
|
|
695
|
+
res.fastEnd = true
|
|
696
|
+
res.wroteHead = true
|
|
697
|
+
res.writeEnded = true
|
|
698
|
+
res.finished = true
|
|
699
|
+
res.closed = true
|
|
700
|
+
return res
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
st := int(res.statusCode)
|
|
704
|
+
if !res.headersSent && !res.wroteData && st >= 200 && st != 204 && st != 304 && !res.store.has("content-length") && !res.store.has("transfer-encoding") {
|
|
483
705
|
size := 0
|
|
484
706
|
if len(args) > 0 {
|
|
485
707
|
switch d := args[0].(type) {
|
|
@@ -511,10 +733,10 @@ func (res *TnServerResponse) setTimeout(ms float64, cb ...interface{}) *TnServer
|
|
|
511
733
|
return res
|
|
512
734
|
}
|
|
513
735
|
|
|
514
|
-
func
|
|
515
|
-
res
|
|
516
|
-
|
|
517
|
-
|
|
736
|
+
func (res *TnServerResponse) tnInitSink() {
|
|
737
|
+
if res.sink != nil {
|
|
738
|
+
return
|
|
739
|
+
}
|
|
518
740
|
res.sink = func(chunk interface{}, done func(err interface{})) {
|
|
519
741
|
if !res.headersSent {
|
|
520
742
|
res.queue(res.headerOp())
|
|
@@ -555,20 +777,359 @@ func tnNewServerResponse(req *TnIncomingMessage) *TnServerResponse {
|
|
|
555
777
|
TnLoopPost(func() { done(nil) })
|
|
556
778
|
}})
|
|
557
779
|
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
func tnNewServerResponse(req *TnIncomingMessage) *TnServerResponse {
|
|
783
|
+
res := &TnServerResponse{statusCode: 200, sendDate: true, req: req}
|
|
784
|
+
res.flowing = -1
|
|
785
|
+
res.decodeStrings = true
|
|
786
|
+
res.writableSide = true
|
|
787
|
+
res.asyncCtx = TnAsyncSnapshot()
|
|
788
|
+
res.tnSelf = res
|
|
558
789
|
return res
|
|
559
790
|
}
|
|
560
791
|
|
|
561
|
-
|
|
792
|
+
type tnHttpConn struct {
|
|
793
|
+
conn net.Conn
|
|
794
|
+
active int32
|
|
795
|
+
closed chan struct{}
|
|
796
|
+
once sync.Once
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
func (hc *tnHttpConn) closeConn() {
|
|
800
|
+
hc.once.Do(func() {
|
|
801
|
+
close(hc.closed)
|
|
802
|
+
hc.conn.Close()
|
|
803
|
+
})
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
var (
|
|
807
|
+
tnDateSec atomic.Int64
|
|
808
|
+
tnDateVal atomic.Value
|
|
809
|
+
tnDateMu sync.Mutex
|
|
810
|
+
)
|
|
811
|
+
|
|
812
|
+
func tnAppendDateHeader(buf []byte) []byte {
|
|
813
|
+
now := time.Now()
|
|
814
|
+
sec := now.Unix()
|
|
815
|
+
if sec == tnDateSec.Load() {
|
|
816
|
+
if s, ok := tnDateVal.Load().(string); ok {
|
|
817
|
+
return append(buf, s...)
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
tnDateMu.Lock()
|
|
821
|
+
if sec != tnDateSec.Load() {
|
|
822
|
+
var b [64]byte
|
|
823
|
+
s := append(b[:0], "Date: "...)
|
|
824
|
+
s = now.UTC().AppendFormat(s, http.TimeFormat)
|
|
825
|
+
s = append(s, '\\r', '\\n')
|
|
826
|
+
tnDateVal.Store(string(s))
|
|
827
|
+
tnDateSec.Store(sec)
|
|
828
|
+
}
|
|
829
|
+
s, _ := tnDateVal.Load().(string)
|
|
830
|
+
tnDateMu.Unlock()
|
|
831
|
+
return append(buf, s...)
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
func tnAppendStatusLine(buf []byte, status int, msg string) []byte {
|
|
835
|
+
if msg == "" {
|
|
836
|
+
switch status {
|
|
837
|
+
case 200:
|
|
838
|
+
return append(buf, "HTTP/1.1 200 OK\\r\\n"...)
|
|
839
|
+
case 201:
|
|
840
|
+
return append(buf, "HTTP/1.1 201 Created\\r\\n"...)
|
|
841
|
+
case 204:
|
|
842
|
+
return append(buf, "HTTP/1.1 204 No Content\\r\\n"...)
|
|
843
|
+
case 400:
|
|
844
|
+
return append(buf, "HTTP/1.1 400 Bad Request\\r\\n"...)
|
|
845
|
+
case 404:
|
|
846
|
+
return append(buf, "HTTP/1.1 404 Not Found\\r\\n"...)
|
|
847
|
+
case 500:
|
|
848
|
+
return append(buf, "HTTP/1.1 500 Internal Server Error\\r\\n"...)
|
|
849
|
+
}
|
|
850
|
+
msg = tnStatusText(status)
|
|
851
|
+
}
|
|
852
|
+
buf = append(buf, "HTTP/1.1 "...)
|
|
853
|
+
buf = strconv.AppendInt(buf, int64(status), 10)
|
|
854
|
+
buf = append(buf, ' ')
|
|
855
|
+
buf = append(buf, msg...)
|
|
856
|
+
return append(buf, '\\r', '\\n')
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
func tnInternMethod(b []byte) string {
|
|
860
|
+
switch len(b) {
|
|
861
|
+
case 3:
|
|
862
|
+
if b[0] == 'G' && b[1] == 'E' && b[2] == 'T' {
|
|
863
|
+
return "GET"
|
|
864
|
+
}
|
|
865
|
+
if b[0] == 'P' && b[1] == 'U' && b[2] == 'T' {
|
|
866
|
+
return "PUT"
|
|
867
|
+
}
|
|
868
|
+
case 4:
|
|
869
|
+
if b[0] == 'P' && b[1] == 'O' && b[2] == 'S' && b[3] == 'T' {
|
|
870
|
+
return "POST"
|
|
871
|
+
}
|
|
872
|
+
if b[0] == 'H' && b[1] == 'E' && b[2] == 'A' && b[3] == 'D' {
|
|
873
|
+
return "HEAD"
|
|
874
|
+
}
|
|
875
|
+
case 5:
|
|
876
|
+
if b[0] == 'P' && b[1] == 'A' && b[2] == 'T' && b[3] == 'C' && b[4] == 'H' {
|
|
877
|
+
return "PATCH"
|
|
878
|
+
}
|
|
879
|
+
case 6:
|
|
880
|
+
if b[0] == 'D' && b[1] == 'E' && b[2] == 'L' && b[3] == 'E' && b[4] == 'T' && b[5] == 'E' {
|
|
881
|
+
return "DELETE"
|
|
882
|
+
}
|
|
883
|
+
case 7:
|
|
884
|
+
if b[0] == 'O' && b[1] == 'P' && b[2] == 'T' && b[3] == 'I' && b[4] == 'O' && b[5] == 'N' && b[6] == 'S' {
|
|
885
|
+
return "OPTIONS"
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
return string(b)
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
type tnHttp1ResponseWriter struct {
|
|
892
|
+
conn net.Conn
|
|
893
|
+
reqMethod string
|
|
894
|
+
protoMinor int
|
|
895
|
+
keepAlive bool
|
|
896
|
+
closeAfter bool
|
|
897
|
+
header http.Header
|
|
898
|
+
status int
|
|
899
|
+
statusMessage string
|
|
900
|
+
hasStatus bool
|
|
901
|
+
wroteHeader bool
|
|
902
|
+
chunked bool
|
|
903
|
+
buf []byte
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
func (w *tnHttp1ResponseWriter) Header() http.Header {
|
|
907
|
+
if w.header == nil {
|
|
908
|
+
w.header = http.Header{}
|
|
909
|
+
}
|
|
910
|
+
return w.header
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
func (w *tnHttp1ResponseWriter) WriteHeader(status int) {
|
|
914
|
+
if w.wroteHeader || w.hasStatus {
|
|
915
|
+
return
|
|
916
|
+
}
|
|
917
|
+
w.status = status
|
|
918
|
+
w.hasStatus = true
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
func (w *tnHttp1ResponseWriter) appendHeaders(ending bool, endLen int) {
|
|
922
|
+
if w.wroteHeader {
|
|
923
|
+
return
|
|
924
|
+
}
|
|
925
|
+
w.wroteHeader = true
|
|
926
|
+
if !w.hasStatus {
|
|
927
|
+
w.status = 200
|
|
928
|
+
w.hasStatus = true
|
|
929
|
+
}
|
|
930
|
+
if w.protoMinor == 0 {
|
|
931
|
+
msg := w.statusMessage
|
|
932
|
+
if msg == "" {
|
|
933
|
+
msg = tnStatusText(w.status)
|
|
934
|
+
}
|
|
935
|
+
w.buf = append(w.buf[:0], "HTTP/1.0 "...)
|
|
936
|
+
w.buf = strconv.AppendInt(w.buf, int64(w.status), 10)
|
|
937
|
+
w.buf = append(w.buf, ' ')
|
|
938
|
+
w.buf = append(w.buf, msg...)
|
|
939
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
940
|
+
} else {
|
|
941
|
+
w.buf = tnAppendStatusLine(w.buf[:0], w.status, w.statusMessage)
|
|
942
|
+
}
|
|
943
|
+
hasCL := false
|
|
944
|
+
hasTE := false
|
|
945
|
+
hasDate := false
|
|
946
|
+
omitDate := false
|
|
947
|
+
hasConn := false
|
|
948
|
+
for k, vals := range w.header {
|
|
949
|
+
if strings.HasPrefix(k, http.TrailerPrefix) {
|
|
950
|
+
continue
|
|
951
|
+
}
|
|
952
|
+
lk := tnLowerASCII(k)
|
|
953
|
+
switch lk {
|
|
954
|
+
case "content-length":
|
|
955
|
+
if len(vals) > 0 {
|
|
956
|
+
hasCL = true
|
|
957
|
+
}
|
|
958
|
+
case "transfer-encoding":
|
|
959
|
+
if len(vals) > 0 {
|
|
960
|
+
hasTE = true
|
|
961
|
+
for _, v := range vals {
|
|
962
|
+
if strings.Contains(strings.ToLower(v), "chunked") {
|
|
963
|
+
w.chunked = true
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
case "date":
|
|
968
|
+
if vals == nil {
|
|
969
|
+
omitDate = true
|
|
970
|
+
} else {
|
|
971
|
+
hasDate = true
|
|
972
|
+
}
|
|
973
|
+
case "connection":
|
|
974
|
+
if len(vals) > 0 {
|
|
975
|
+
hasConn = true
|
|
976
|
+
for _, v := range vals {
|
|
977
|
+
if strings.Contains(strings.ToLower(v), "close") {
|
|
978
|
+
w.closeAfter = true
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
for _, v := range vals {
|
|
984
|
+
w.buf = append(w.buf, k...)
|
|
985
|
+
w.buf = append(w.buf, ':', ' ')
|
|
986
|
+
w.buf = append(w.buf, v...)
|
|
987
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
if !hasDate && !omitDate {
|
|
991
|
+
w.buf = tnAppendDateHeader(w.buf)
|
|
992
|
+
}
|
|
993
|
+
noBody := w.reqMethod == "HEAD" || w.status < 200 || w.status == 204 || w.status == 304
|
|
994
|
+
if !noBody && !hasCL && !hasTE {
|
|
995
|
+
if ending {
|
|
996
|
+
w.buf = append(w.buf, "Content-Length: "...)
|
|
997
|
+
w.buf = strconv.AppendInt(w.buf, int64(endLen), 10)
|
|
998
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
999
|
+
} else if w.protoMinor >= 1 {
|
|
1000
|
+
w.chunked = true
|
|
1001
|
+
w.buf = append(w.buf, "Transfer-Encoding: chunked\\r\\n"...)
|
|
1002
|
+
} else {
|
|
1003
|
+
w.closeAfter = true
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
if !hasConn {
|
|
1007
|
+
if !w.keepAlive || w.closeAfter {
|
|
1008
|
+
w.buf = append(w.buf, "Connection: close\\r\\n"...)
|
|
1009
|
+
} else if w.protoMinor == 0 {
|
|
1010
|
+
w.buf = append(w.buf, "Connection: keep-alive\\r\\n"...)
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
func (w *tnHttp1ResponseWriter) Flush() error {
|
|
1017
|
+
if !w.wroteHeader {
|
|
1018
|
+
w.appendHeaders(false, 0)
|
|
1019
|
+
_, err := w.conn.Write(w.buf)
|
|
1020
|
+
return err
|
|
1021
|
+
}
|
|
1022
|
+
return nil
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
func (w *tnHttp1ResponseWriter) Write(data []byte) (int, error) {
|
|
1026
|
+
noBody := w.reqMethod == "HEAD" || (w.hasStatus && (w.status < 200 || w.status == 204 || w.status == 304))
|
|
1027
|
+
if !w.wroteHeader {
|
|
1028
|
+
w.appendHeaders(false, 0)
|
|
1029
|
+
if noBody || len(data) == 0 {
|
|
1030
|
+
_, err := w.conn.Write(w.buf)
|
|
1031
|
+
return len(data), err
|
|
1032
|
+
}
|
|
1033
|
+
if w.chunked {
|
|
1034
|
+
w.buf = strconv.AppendInt(w.buf, int64(len(data)), 16)
|
|
1035
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
1036
|
+
w.buf = append(w.buf, data...)
|
|
1037
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
1038
|
+
} else {
|
|
1039
|
+
w.buf = append(w.buf, data...)
|
|
1040
|
+
}
|
|
1041
|
+
_, err := w.conn.Write(w.buf)
|
|
1042
|
+
return len(data), err
|
|
1043
|
+
}
|
|
1044
|
+
if noBody || len(data) == 0 {
|
|
1045
|
+
return len(data), nil
|
|
1046
|
+
}
|
|
1047
|
+
w.buf = w.buf[:0]
|
|
1048
|
+
if w.chunked {
|
|
1049
|
+
w.buf = strconv.AppendInt(w.buf, int64(len(data)), 16)
|
|
1050
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
1051
|
+
w.buf = append(w.buf, data...)
|
|
1052
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
1053
|
+
_, err := w.conn.Write(w.buf)
|
|
1054
|
+
return len(data), err
|
|
1055
|
+
}
|
|
1056
|
+
return w.conn.Write(data)
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
func (w *tnHttp1ResponseWriter) finish(data []byte, trailer http.Header) error {
|
|
1060
|
+
if !w.wroteHeader {
|
|
1061
|
+
w.appendHeaders(true, len(data))
|
|
1062
|
+
noBody := w.reqMethod == "HEAD" || w.status < 200 || w.status == 204 || w.status == 304
|
|
1063
|
+
if !noBody {
|
|
1064
|
+
if w.chunked {
|
|
1065
|
+
if len(data) > 0 {
|
|
1066
|
+
w.buf = strconv.AppendInt(w.buf, int64(len(data)), 16)
|
|
1067
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
1068
|
+
w.buf = append(w.buf, data...)
|
|
1069
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
1070
|
+
}
|
|
1071
|
+
w.buf = append(w.buf, "0\\r\\n"...)
|
|
1072
|
+
for k, vals := range trailer {
|
|
1073
|
+
for _, v := range vals {
|
|
1074
|
+
w.buf = append(w.buf, k...)
|
|
1075
|
+
w.buf = append(w.buf, ':', ' ')
|
|
1076
|
+
w.buf = append(w.buf, v...)
|
|
1077
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
1081
|
+
} else if len(data) > 0 {
|
|
1082
|
+
w.buf = append(w.buf, data...)
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
_, err := w.conn.Write(w.buf)
|
|
1086
|
+
return err
|
|
1087
|
+
}
|
|
1088
|
+
noBody := w.reqMethod == "HEAD" || w.status < 200 || w.status == 204 || w.status == 304
|
|
1089
|
+
w.buf = w.buf[:0]
|
|
1090
|
+
if !noBody {
|
|
1091
|
+
if w.chunked {
|
|
1092
|
+
if len(data) > 0 {
|
|
1093
|
+
w.buf = strconv.AppendInt(w.buf, int64(len(data)), 16)
|
|
1094
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
1095
|
+
w.buf = append(w.buf, data...)
|
|
1096
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
1097
|
+
}
|
|
1098
|
+
w.buf = append(w.buf, "0\\r\\n"...)
|
|
1099
|
+
for k, vals := range trailer {
|
|
1100
|
+
for _, v := range vals {
|
|
1101
|
+
w.buf = append(w.buf, k...)
|
|
1102
|
+
w.buf = append(w.buf, ':', ' ')
|
|
1103
|
+
w.buf = append(w.buf, v...)
|
|
1104
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
w.buf = append(w.buf, '\\r', '\\n')
|
|
1108
|
+
} else if len(data) > 0 {
|
|
1109
|
+
w.buf = append(w.buf, data...)
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
if len(w.buf) > 0 {
|
|
1113
|
+
_, err := w.conn.Write(w.buf)
|
|
1114
|
+
return err
|
|
1115
|
+
}
|
|
1116
|
+
return nil
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// http.Server: a net.Server whose connections are served directly (HTTP/1.x) or by net/http (HTTP/2)
|
|
562
1120
|
type TnHttpServer struct {
|
|
563
1121
|
TnNetServer
|
|
564
|
-
httpServer
|
|
565
|
-
tlsConfig
|
|
566
|
-
inFlight
|
|
567
|
-
|
|
1122
|
+
httpServer *http.Server
|
|
1123
|
+
tlsConfig *tls.Config
|
|
1124
|
+
inFlight sync.WaitGroup
|
|
1125
|
+
connMu sync.Mutex
|
|
1126
|
+
httpConns map[*tnHttpConn]struct{}
|
|
1127
|
+
closing int32
|
|
1128
|
+
timeout float64
|
|
568
1129
|
keepAliveTimeout float64
|
|
569
|
-
headersTimeout
|
|
570
|
-
requestTimeout
|
|
571
|
-
maxHeadersCount
|
|
1130
|
+
headersTimeout float64
|
|
1131
|
+
requestTimeout float64
|
|
1132
|
+
maxHeadersCount interface{}
|
|
572
1133
|
// node:http2 servers (pseudo-headers, the 'stream' API)
|
|
573
1134
|
h2 bool
|
|
574
1135
|
}
|
|
@@ -576,20 +1137,524 @@ type TnHttpServer struct {
|
|
|
576
1137
|
// Set by node:http2: serves an HTTP/2 request through the 'stream' API (false when not handled)
|
|
577
1138
|
var tnHttp2StreamHook func(hs *TnHttpServer, w http.ResponseWriter, r *http.Request) bool
|
|
578
1139
|
|
|
579
|
-
func (hs *TnHttpServer) Get_timeout() float64
|
|
580
|
-
func (hs *TnHttpServer) Set_timeout(v float64)
|
|
581
|
-
func (hs *TnHttpServer) Get_keepAliveTimeout() float64
|
|
1140
|
+
func (hs *TnHttpServer) Get_timeout() float64 { return hs.timeout }
|
|
1141
|
+
func (hs *TnHttpServer) Set_timeout(v float64) { hs.timeout = v }
|
|
1142
|
+
func (hs *TnHttpServer) Get_keepAliveTimeout() float64 { return hs.keepAliveTimeout }
|
|
582
1143
|
func (hs *TnHttpServer) Set_keepAliveTimeout(v float64) { hs.keepAliveTimeout = v }
|
|
583
|
-
func (hs *TnHttpServer) Get_headersTimeout() float64
|
|
584
|
-
func (hs *TnHttpServer) Set_headersTimeout(v float64)
|
|
585
|
-
func (hs *TnHttpServer) Get_requestTimeout() float64
|
|
586
|
-
func (hs *TnHttpServer) Set_requestTimeout(v float64)
|
|
1144
|
+
func (hs *TnHttpServer) Get_headersTimeout() float64 { return hs.headersTimeout }
|
|
1145
|
+
func (hs *TnHttpServer) Set_headersTimeout(v float64) { hs.headersTimeout = v }
|
|
1146
|
+
func (hs *TnHttpServer) Get_requestTimeout() float64 { return hs.requestTimeout }
|
|
1147
|
+
func (hs *TnHttpServer) Set_requestTimeout(v float64) { hs.requestTimeout = v }
|
|
587
1148
|
|
|
588
1149
|
func (hs *TnHttpServer) setTimeout(ms float64, cb ...interface{}) *TnHttpServer {
|
|
589
1150
|
hs.timeout = ms
|
|
590
1151
|
return hs
|
|
591
1152
|
}
|
|
592
1153
|
|
|
1154
|
+
func (hs *TnHttpServer) serveConn(hc *tnHttpConn, local net.Addr) {
|
|
1155
|
+
upgraded := false
|
|
1156
|
+
defer func() {
|
|
1157
|
+
if !upgraded {
|
|
1158
|
+
hc.closeConn()
|
|
1159
|
+
}
|
|
1160
|
+
hs.connMu.Lock()
|
|
1161
|
+
delete(hs.httpConns, hc)
|
|
1162
|
+
hs.connMu.Unlock()
|
|
1163
|
+
hs.inFlight.Done()
|
|
1164
|
+
}()
|
|
1165
|
+
if tc, ok := hc.conn.(*tls.Conn); ok {
|
|
1166
|
+
if err := tc.Handshake(); err != nil {
|
|
1167
|
+
return
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
remoteAddr := ""
|
|
1171
|
+
if ra := hc.conn.RemoteAddr(); ra != nil {
|
|
1172
|
+
remoteAddr = ra.String()
|
|
1173
|
+
}
|
|
1174
|
+
br := bufio.NewReaderSize(hc.conn, 8192)
|
|
1175
|
+
outBuf := make([]byte, 0, 4096)
|
|
1176
|
+
for {
|
|
1177
|
+
atomic.StoreInt32(&hc.active, 0)
|
|
1178
|
+
if atomic.LoadInt32(&hs.closing) != 0 {
|
|
1179
|
+
return
|
|
1180
|
+
}
|
|
1181
|
+
if _, err := br.Peek(1); err != nil {
|
|
1182
|
+
return
|
|
1183
|
+
}
|
|
1184
|
+
atomic.StoreInt32(&hc.active, 1)
|
|
1185
|
+
if atomic.LoadInt32(&hs.closing) != 0 {
|
|
1186
|
+
return
|
|
1187
|
+
}
|
|
1188
|
+
if handled, ka := hs.tryFastHTTP1(hc, br, local, remoteAddr, &outBuf); handled {
|
|
1189
|
+
if !ka || atomic.LoadInt32(&hs.closing) != 0 {
|
|
1190
|
+
return
|
|
1191
|
+
}
|
|
1192
|
+
continue
|
|
1193
|
+
}
|
|
1194
|
+
r, err := http.ReadRequest(br)
|
|
1195
|
+
if err != nil {
|
|
1196
|
+
return
|
|
1197
|
+
}
|
|
1198
|
+
ka, upg := hs.serveHTTP1(hc, br, r, local, remoteAddr)
|
|
1199
|
+
if upg {
|
|
1200
|
+
upgraded = true
|
|
1201
|
+
return
|
|
1202
|
+
}
|
|
1203
|
+
if !ka || atomic.LoadInt32(&hs.closing) != 0 {
|
|
1204
|
+
return
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
func (hs *TnHttpServer) tryFastHTTP1(hc *tnHttpConn, br *bufio.Reader, local net.Addr, remoteAddr string, outBuf *[]byte) (bool, bool) {
|
|
1210
|
+
n := br.Buffered()
|
|
1211
|
+
if n < 16 {
|
|
1212
|
+
return false, false
|
|
1213
|
+
}
|
|
1214
|
+
buf, _ := br.Peek(n)
|
|
1215
|
+
hdrEnd := bytes.Index(buf, []byte("\\r\\n\\r\\n"))
|
|
1216
|
+
if hdrEnd < 0 {
|
|
1217
|
+
return false, false
|
|
1218
|
+
}
|
|
1219
|
+
lineEnd := bytes.Index(buf[:hdrEnd], []byte("\\r\\n"))
|
|
1220
|
+
if lineEnd < 0 {
|
|
1221
|
+
return false, false
|
|
1222
|
+
}
|
|
1223
|
+
reqLine := buf[:lineEnd]
|
|
1224
|
+
sp1 := bytes.IndexByte(reqLine, ' ')
|
|
1225
|
+
if sp1 <= 0 {
|
|
1226
|
+
return false, false
|
|
1227
|
+
}
|
|
1228
|
+
sp2 := bytes.IndexByte(reqLine[sp1+1:], ' ')
|
|
1229
|
+
if sp2 <= 0 {
|
|
1230
|
+
return false, false
|
|
1231
|
+
}
|
|
1232
|
+
sp2 += sp1 + 1
|
|
1233
|
+
proto := reqLine[sp2+1:]
|
|
1234
|
+
if len(proto) != 8 || proto[0] != 'H' || proto[1] != 'T' || proto[2] != 'T' || proto[3] != 'P' || proto[4] != '/' || proto[5] != '1' || proto[6] != '.' || proto[7] != '1' {
|
|
1235
|
+
return false, false
|
|
1236
|
+
}
|
|
1237
|
+
methodBytes := reqLine[:sp1]
|
|
1238
|
+
if len(methodBytes) == 7 && string(methodBytes) == "CONNECT" {
|
|
1239
|
+
return false, false
|
|
1240
|
+
}
|
|
1241
|
+
hdrBlock := buf[lineEnd+2 : hdrEnd]
|
|
1242
|
+
contentLen := 0
|
|
1243
|
+
keepAlive := true
|
|
1244
|
+
rest := hdrBlock
|
|
1245
|
+
for len(rest) > 0 {
|
|
1246
|
+
nl := bytes.IndexByte(rest, '\\n')
|
|
1247
|
+
var line []byte
|
|
1248
|
+
if nl < 0 {
|
|
1249
|
+
line = rest
|
|
1250
|
+
rest = nil
|
|
1251
|
+
} else {
|
|
1252
|
+
line = rest[:nl]
|
|
1253
|
+
rest = rest[nl+1:]
|
|
1254
|
+
}
|
|
1255
|
+
if len(line) > 0 && line[len(line)-1] == '\\r' {
|
|
1256
|
+
line = line[:len(line)-1]
|
|
1257
|
+
}
|
|
1258
|
+
colon := bytes.IndexByte(line, ':')
|
|
1259
|
+
if colon <= 0 {
|
|
1260
|
+
return false, false
|
|
1261
|
+
}
|
|
1262
|
+
k := line[:colon]
|
|
1263
|
+
v := line[colon+1:]
|
|
1264
|
+
for len(v) > 0 && (v[0] == ' ' || v[0] == '\\t') {
|
|
1265
|
+
v = v[1:]
|
|
1266
|
+
}
|
|
1267
|
+
for len(v) > 0 && (v[len(v)-1] == ' ' || v[len(v)-1] == '\\t') {
|
|
1268
|
+
v = v[:len(v)-1]
|
|
1269
|
+
}
|
|
1270
|
+
switch len(k) {
|
|
1271
|
+
case 6: // Expect
|
|
1272
|
+
if (k[0]|0x20) == 'e' && strings.EqualFold(string(k), "expect") {
|
|
1273
|
+
return false, false
|
|
1274
|
+
}
|
|
1275
|
+
case 7: // Upgrade
|
|
1276
|
+
if (k[0]|0x20) == 'u' && strings.EqualFold(string(k), "upgrade") {
|
|
1277
|
+
return false, false
|
|
1278
|
+
}
|
|
1279
|
+
case 10: // Connection
|
|
1280
|
+
if (k[0]|0x20) == 'c' && strings.EqualFold(string(k), "connection") {
|
|
1281
|
+
if len(v) == 10 && (v[0]|0x20) == 'k' {
|
|
1282
|
+
// keep-alive
|
|
1283
|
+
} else if len(v) == 5 && (v[0]|0x20) == 'c' && strings.EqualFold(string(v), "close") {
|
|
1284
|
+
keepAlive = false
|
|
1285
|
+
} else {
|
|
1286
|
+
lv := bytes.ToLower(v)
|
|
1287
|
+
if bytes.Contains(lv, []byte("upgrade")) {
|
|
1288
|
+
return false, false
|
|
1289
|
+
}
|
|
1290
|
+
if bytes.Contains(lv, []byte("close")) {
|
|
1291
|
+
keepAlive = false
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
case 14: // Content-Length
|
|
1296
|
+
if (k[0]|0x20) == 'c' && (k[8]|0x20) == 'l' && strings.EqualFold(string(k), "content-length") {
|
|
1297
|
+
if len(v) == 0 {
|
|
1298
|
+
return false, false
|
|
1299
|
+
}
|
|
1300
|
+
cl := 0
|
|
1301
|
+
for i := 0; i < len(v); i++ {
|
|
1302
|
+
if v[i] < '0' || v[i] > '9' {
|
|
1303
|
+
return false, false
|
|
1304
|
+
}
|
|
1305
|
+
cl = cl*10 + int(v[i]-'0')
|
|
1306
|
+
if cl > 65536 {
|
|
1307
|
+
return false, false
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
contentLen = cl
|
|
1311
|
+
}
|
|
1312
|
+
case 17: // Transfer-Encoding
|
|
1313
|
+
if (k[0]|0x20) == 't' && strings.EqualFold(string(k), "transfer-encoding") {
|
|
1314
|
+
return false, false
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
totalLen := hdrEnd + 4 + contentLen
|
|
1319
|
+
if n < totalLen {
|
|
1320
|
+
if totalLen > 8192 {
|
|
1321
|
+
return false, false
|
|
1322
|
+
}
|
|
1323
|
+
if _, err := br.Peek(totalLen); err != nil {
|
|
1324
|
+
return false, false
|
|
1325
|
+
}
|
|
1326
|
+
buf, _ = br.Peek(totalLen)
|
|
1327
|
+
hdrBlock = buf[lineEnd+2 : hdrEnd]
|
|
1328
|
+
}
|
|
1329
|
+
var body []byte
|
|
1330
|
+
if contentLen > 0 {
|
|
1331
|
+
body = make([]byte, contentLen)
|
|
1332
|
+
copy(body, buf[hdrEnd+4:totalLen])
|
|
1333
|
+
}
|
|
1334
|
+
method := tnInternMethod(buf[:sp1])
|
|
1335
|
+
reqURL := string(buf[sp1+1 : sp2])
|
|
1336
|
+
|
|
1337
|
+
var req *TnIncomingMessage
|
|
1338
|
+
var res *TnServerResponse
|
|
1339
|
+
tnLoopRun(func() {
|
|
1340
|
+
prevCtx := tnAsyncCtx
|
|
1341
|
+
tnAsyncCtx = hs.asyncCtx
|
|
1342
|
+
defer func() { tnAsyncCtx = prevCtx }()
|
|
1343
|
+
|
|
1344
|
+
req = tnNewIncoming()
|
|
1345
|
+
req.method = method
|
|
1346
|
+
req.url = reqURL
|
|
1347
|
+
req.httpVersion = "1.1"
|
|
1348
|
+
req.httpVersionMajor = 1
|
|
1349
|
+
req.httpVersionMinor = 1
|
|
1350
|
+
req.rawHeaderBlock = hdrBlock
|
|
1351
|
+
req.rawTLS = hs.tlsConfig != nil
|
|
1352
|
+
req.rawLocal = local
|
|
1353
|
+
req.rawRemote = remoteAddr
|
|
1354
|
+
|
|
1355
|
+
res = tnNewServerResponse(req)
|
|
1356
|
+
res.inSyncTurn = true
|
|
1357
|
+
req.flowScheduled = true
|
|
1358
|
+
hs.emit("request", req, res)
|
|
1359
|
+
if !req.destroyed && req.flowing == 1 && !req.readableListening && len(req.queue) == 0 && req.decoder == nil {
|
|
1360
|
+
if len(body) > 0 {
|
|
1361
|
+
req.bytesRead += float64(len(body))
|
|
1362
|
+
if req.state == nil {
|
|
1363
|
+
if req.fn0 != nil && req.ev0 == "data" {
|
|
1364
|
+
if f, ok := req.fn0.(func([]byte)); ok {
|
|
1365
|
+
f(body)
|
|
1366
|
+
} else if f, ok := req.fn0.(func(interface{})); ok {
|
|
1367
|
+
f(body)
|
|
1368
|
+
} else {
|
|
1369
|
+
TnInvoke(req.fn0, body)
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
if req.fn1 != nil && req.ev1 == "data" {
|
|
1373
|
+
if f, ok := req.fn1.(func([]byte)); ok {
|
|
1374
|
+
f(body)
|
|
1375
|
+
} else if f, ok := req.fn1.(func(interface{})); ok {
|
|
1376
|
+
f(body)
|
|
1377
|
+
} else {
|
|
1378
|
+
TnInvoke(req.fn1, body)
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
} else {
|
|
1382
|
+
req.emit("data", body)
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
if !req.destroyed && req.flowing == 1 && len(req.queue) == 0 {
|
|
1386
|
+
req.complete = true
|
|
1387
|
+
req.readEnded = true
|
|
1388
|
+
req.flowScheduled = false
|
|
1389
|
+
req.emitEnd()
|
|
1390
|
+
} else {
|
|
1391
|
+
req.complete = true
|
|
1392
|
+
req.push(nil)
|
|
1393
|
+
req.flowScheduled = false
|
|
1394
|
+
if !req.destroyed {
|
|
1395
|
+
req.flow()
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
} else {
|
|
1399
|
+
if !req.destroyed {
|
|
1400
|
+
if len(body) > 0 {
|
|
1401
|
+
req.push(body)
|
|
1402
|
+
}
|
|
1403
|
+
req.complete = true
|
|
1404
|
+
req.push(nil)
|
|
1405
|
+
}
|
|
1406
|
+
req.flowScheduled = false
|
|
1407
|
+
if !req.destroyed {
|
|
1408
|
+
req.flow()
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
TnRunMicrotasks()
|
|
1412
|
+
res.inSyncTurn = false
|
|
1413
|
+
})
|
|
1414
|
+
|
|
1415
|
+
if !res.fastEnd && req.hdrs == nil && len(req.rawHeaderBlock) > 0 {
|
|
1416
|
+
req.rawHeaderBlock = append([]byte(nil), req.rawHeaderBlock...)
|
|
1417
|
+
}
|
|
1418
|
+
br.Discard(totalLen)
|
|
1419
|
+
|
|
1420
|
+
if res.fastEnd {
|
|
1421
|
+
status := int(res.statusCode)
|
|
1422
|
+
b := tnAppendStatusLine((*outBuf)[:0], status, res.statusMessage)
|
|
1423
|
+
hasCL := false
|
|
1424
|
+
hasTE := false
|
|
1425
|
+
hasDate := false
|
|
1426
|
+
hasConn := false
|
|
1427
|
+
for i := range res.store.entries {
|
|
1428
|
+
e := &res.store.entries[i]
|
|
1429
|
+
switch e.key {
|
|
1430
|
+
case "content-length":
|
|
1431
|
+
hasCL = true
|
|
1432
|
+
case "transfer-encoding":
|
|
1433
|
+
hasTE = true
|
|
1434
|
+
case "date":
|
|
1435
|
+
hasDate = true
|
|
1436
|
+
case "connection":
|
|
1437
|
+
hasConn = true
|
|
1438
|
+
if s, ok := e.value.(string); ok && strings.Contains(strings.ToLower(s), "close") {
|
|
1439
|
+
keepAlive = false
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
if s, ok := e.value.(string); ok {
|
|
1443
|
+
b = append(b, e.name...)
|
|
1444
|
+
b = append(b, ':', ' ')
|
|
1445
|
+
b = append(b, s...)
|
|
1446
|
+
b = append(b, '\\r', '\\n')
|
|
1447
|
+
} else if num, ok := e.value.(float64); ok {
|
|
1448
|
+
b = append(b, e.name...)
|
|
1449
|
+
b = append(b, ':', ' ')
|
|
1450
|
+
b = strconv.AppendFloat(b, num, 'f', -1, 64)
|
|
1451
|
+
b = append(b, '\\r', '\\n')
|
|
1452
|
+
} else {
|
|
1453
|
+
for _, v := range tnHeaderStrings(e.value) {
|
|
1454
|
+
b = append(b, e.name...)
|
|
1455
|
+
b = append(b, ':', ' ')
|
|
1456
|
+
b = append(b, v...)
|
|
1457
|
+
b = append(b, '\\r', '\\n')
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
if res.sendDate && !hasDate {
|
|
1462
|
+
b = tnAppendDateHeader(b)
|
|
1463
|
+
}
|
|
1464
|
+
if !keepAlive && !hasConn {
|
|
1465
|
+
b = append(b, "Connection: close\\r\\n"...)
|
|
1466
|
+
}
|
|
1467
|
+
noBody := req.method == "HEAD" || status < 200 || status == 204 || status == 304
|
|
1468
|
+
if !noBody && !hasCL && !hasTE {
|
|
1469
|
+
b = append(b, "Content-Length: "...)
|
|
1470
|
+
b = strconv.AppendInt(b, int64(len(res.fastBody)), 10)
|
|
1471
|
+
b = append(b, '\\r', '\\n')
|
|
1472
|
+
}
|
|
1473
|
+
b = append(b, '\\r', '\\n')
|
|
1474
|
+
if !noBody && len(res.fastBody) > 0 {
|
|
1475
|
+
b = append(b, res.fastBody...)
|
|
1476
|
+
}
|
|
1477
|
+
*outBuf = b
|
|
1478
|
+
if _, err := hc.conn.Write(b); err != nil {
|
|
1479
|
+
return true, false
|
|
1480
|
+
}
|
|
1481
|
+
return true, keepAlive
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
w := &tnHttp1ResponseWriter{
|
|
1485
|
+
conn: hc.conn,
|
|
1486
|
+
reqMethod: req.method,
|
|
1487
|
+
protoMinor: 1,
|
|
1488
|
+
keepAlive: keepAlive,
|
|
1489
|
+
buf: (*outBuf)[:0],
|
|
1490
|
+
}
|
|
1491
|
+
closedDone := make(chan struct{})
|
|
1492
|
+
close(closedDone)
|
|
1493
|
+
tnServeOps1(w, hc, res, func() {
|
|
1494
|
+
if !res.finished {
|
|
1495
|
+
req.aborted = true
|
|
1496
|
+
res.destroy()
|
|
1497
|
+
}
|
|
1498
|
+
}, closedDone)
|
|
1499
|
+
*outBuf = w.buf[:0]
|
|
1500
|
+
return true, w.keepAlive && !w.closeAfter
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
func (hs *TnHttpServer) serveUpgrade1(hc *tnHttpConn, br *bufio.Reader, r *http.Request, local net.Addr) (bool, bool) {
|
|
1504
|
+
event := ""
|
|
1505
|
+
if r.Method == http.MethodConnect {
|
|
1506
|
+
event = "connect"
|
|
1507
|
+
} else if r.Header.Get("Upgrade") != "" && tnHeaderHasToken(r.Header, "Connection", "upgrade") {
|
|
1508
|
+
event = "upgrade"
|
|
1509
|
+
}
|
|
1510
|
+
if event == "" {
|
|
1511
|
+
return false, false
|
|
1512
|
+
}
|
|
1513
|
+
listening := false
|
|
1514
|
+
tnLoopRun(func() { listening = hs.listenerCount(event) > 0 })
|
|
1515
|
+
if !listening {
|
|
1516
|
+
if event == "upgrade" {
|
|
1517
|
+
return false, false
|
|
1518
|
+
}
|
|
1519
|
+
return true, false
|
|
1520
|
+
}
|
|
1521
|
+
head := []byte{}
|
|
1522
|
+
if n := br.Buffered(); n > 0 {
|
|
1523
|
+
peeked, _ := br.Peek(n)
|
|
1524
|
+
head = append(head, peeked...)
|
|
1525
|
+
}
|
|
1526
|
+
tnLoopRun(func() {
|
|
1527
|
+
TnAsyncRun(hs.asyncCtx, func() {
|
|
1528
|
+
req := hs.incoming(r, local)
|
|
1529
|
+
req.complete = true
|
|
1530
|
+
req.push(nil)
|
|
1531
|
+
socket := TnNewSocket()
|
|
1532
|
+
socket.attach(hc.conn)
|
|
1533
|
+
if r.TLS != nil {
|
|
1534
|
+
socket.encrypted = true
|
|
1535
|
+
}
|
|
1536
|
+
req.socket = socket
|
|
1537
|
+
hs.emit(event, req, socket, head)
|
|
1538
|
+
})
|
|
1539
|
+
})
|
|
1540
|
+
return true, true
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
func (hs *TnHttpServer) serveHTTP1(hc *tnHttpConn, br *bufio.Reader, r *http.Request, local net.Addr, remoteAddr string) (bool, bool) {
|
|
1544
|
+
TnLoopRef()
|
|
1545
|
+
defer TnLoopUnref()
|
|
1546
|
+
r.RemoteAddr = remoteAddr
|
|
1547
|
+
if hs.tlsConfig != nil {
|
|
1548
|
+
if tc, ok := hc.conn.(*tls.Conn); ok {
|
|
1549
|
+
st := tc.ConnectionState()
|
|
1550
|
+
r.TLS = &st
|
|
1551
|
+
} else {
|
|
1552
|
+
r.TLS = &tls.ConnectionState{}
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
if handled, upg := hs.serveUpgrade1(hc, br, r, local); handled {
|
|
1556
|
+
return false, upg
|
|
1557
|
+
}
|
|
1558
|
+
if r.Header.Get("Expect") != "" && strings.EqualFold(r.Header.Get("Expect"), "100-continue") {
|
|
1559
|
+
hc.conn.Write([]byte("HTTP/1.1 100 Continue\\r\\n\\r\\n"))
|
|
1560
|
+
}
|
|
1561
|
+
bodyDone := make(chan struct{})
|
|
1562
|
+
var small []byte
|
|
1563
|
+
var smallErr error
|
|
1564
|
+
if r.ContentLength > 0 && r.ContentLength <= 65536 && r.Header.Get("Expect") == "" {
|
|
1565
|
+
small = make([]byte, r.ContentLength)
|
|
1566
|
+
_, smallErr = io.ReadFull(r.Body, small)
|
|
1567
|
+
r.Body.Close()
|
|
1568
|
+
}
|
|
1569
|
+
var req *TnIncomingMessage
|
|
1570
|
+
var res *TnServerResponse
|
|
1571
|
+
tnLoopRun(func() {
|
|
1572
|
+
TnAsyncRun(hs.asyncCtx, func() {
|
|
1573
|
+
req = hs.incoming(r, local)
|
|
1574
|
+
res = tnNewServerResponse(req)
|
|
1575
|
+
hs.emit("request", req, res)
|
|
1576
|
+
if small != nil {
|
|
1577
|
+
if smallErr != nil {
|
|
1578
|
+
req.aborted = true
|
|
1579
|
+
req.destroy(TnNodeError("Error", "ECONNRESET", "aborted"))
|
|
1580
|
+
} else {
|
|
1581
|
+
req.push(small)
|
|
1582
|
+
req.complete = true
|
|
1583
|
+
req.push(nil)
|
|
1584
|
+
}
|
|
1585
|
+
close(bodyDone)
|
|
1586
|
+
} else if r.Body == nil || r.Body == http.NoBody {
|
|
1587
|
+
req.complete = true
|
|
1588
|
+
req.push(nil)
|
|
1589
|
+
close(bodyDone)
|
|
1590
|
+
} else {
|
|
1591
|
+
tnPumpBody(r.Body, req, nil, func() { close(bodyDone) })
|
|
1592
|
+
}
|
|
1593
|
+
})
|
|
1594
|
+
})
|
|
1595
|
+
keepAlive := !r.Close && (r.ProtoMajor > 1 || (r.ProtoMajor == 1 && r.ProtoMinor >= 1) || tnHeaderHasToken(r.Header, "Connection", "keep-alive"))
|
|
1596
|
+
w := &tnHttp1ResponseWriter{
|
|
1597
|
+
conn: hc.conn,
|
|
1598
|
+
reqMethod: r.Method,
|
|
1599
|
+
protoMinor: r.ProtoMinor,
|
|
1600
|
+
keepAlive: keepAlive,
|
|
1601
|
+
}
|
|
1602
|
+
tnServeOps1(w, hc, res, func() {
|
|
1603
|
+
if !res.finished {
|
|
1604
|
+
req.aborted = true
|
|
1605
|
+
res.destroy()
|
|
1606
|
+
}
|
|
1607
|
+
}, bodyDone)
|
|
1608
|
+
if r.Body != nil {
|
|
1609
|
+
r.Body.Close()
|
|
1610
|
+
}
|
|
1611
|
+
return w.keepAlive && !w.closeAfter, false
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
func tnServeOps1(w *tnHttp1ResponseWriter, hc *tnHttpConn, res *TnServerResponse, abort func(), bodyDone chan struct{}) {
|
|
1615
|
+
for {
|
|
1616
|
+
ended := false
|
|
1617
|
+
for _, op := range res.take() {
|
|
1618
|
+
switch {
|
|
1619
|
+
case op.header != nil:
|
|
1620
|
+
for k, v := range op.header {
|
|
1621
|
+
if v == nil {
|
|
1622
|
+
w.Header()[k] = nil
|
|
1623
|
+
} else {
|
|
1624
|
+
w.Header()[k] = v
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
w.statusMessage = op.statusMsg
|
|
1628
|
+
w.WriteHeader(op.status)
|
|
1629
|
+
if op.flush {
|
|
1630
|
+
w.Flush()
|
|
1631
|
+
}
|
|
1632
|
+
case op.end:
|
|
1633
|
+
err := w.finish(op.data, op.trailer)
|
|
1634
|
+
ended = true
|
|
1635
|
+
op.done(err)
|
|
1636
|
+
default:
|
|
1637
|
+
_, err := w.Write(op.data)
|
|
1638
|
+
if err == nil {
|
|
1639
|
+
err = w.Flush()
|
|
1640
|
+
}
|
|
1641
|
+
op.done(err)
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
if ended {
|
|
1645
|
+
break
|
|
1646
|
+
}
|
|
1647
|
+
select {
|
|
1648
|
+
case <-res.sig():
|
|
1649
|
+
case <-hc.closed:
|
|
1650
|
+
TnLoopPost(abort)
|
|
1651
|
+
<-bodyDone
|
|
1652
|
+
return
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
<-bodyDone
|
|
1656
|
+
}
|
|
1657
|
+
|
|
593
1658
|
func (hs *TnHttpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
594
1659
|
if hs.h2 && tnHttp2StreamHook != nil && tnHttp2StreamHook(hs, w, r) {
|
|
595
1660
|
return
|
|
@@ -620,10 +1685,6 @@ func (hs *TnHttpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
620
1685
|
tnLoopRunOrPost(func() {
|
|
621
1686
|
TnAsyncRun(hs.asyncCtx, func() {
|
|
622
1687
|
req := hs.incoming(r, local)
|
|
623
|
-
req.socket = tnInfoSocket(local, r.RemoteAddr)
|
|
624
|
-
if r.TLS != nil {
|
|
625
|
-
req.socket.encrypted = true
|
|
626
|
-
}
|
|
627
1688
|
res := tnNewServerResponse(req)
|
|
628
1689
|
created <- res
|
|
629
1690
|
hs.emit("request", req, res)
|
|
@@ -662,12 +1723,21 @@ func (hs *TnHttpServer) incoming(r *http.Request, local net.Addr) *TnIncomingMes
|
|
|
662
1723
|
req := tnNewIncoming()
|
|
663
1724
|
req.method = r.Method
|
|
664
1725
|
req.url = r.RequestURI
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
1726
|
+
if r.ProtoMajor == 1 && r.ProtoMinor == 1 {
|
|
1727
|
+
req.httpVersion = "1.1"
|
|
1728
|
+
} else if r.ProtoMajor == 1 && r.ProtoMinor == 0 {
|
|
1729
|
+
req.httpVersion = "1.0"
|
|
1730
|
+
} else {
|
|
1731
|
+
req.httpVersion = strconv.Itoa(r.ProtoMajor) + "." + strconv.Itoa(r.ProtoMinor)
|
|
670
1732
|
}
|
|
1733
|
+
req.httpVersionMajor, req.httpVersionMinor = float64(r.ProtoMajor), float64(r.ProtoMinor)
|
|
1734
|
+
req.rawGoHeader = r.Header
|
|
1735
|
+
req.rawHost = r.Host
|
|
1736
|
+
req.rawChunked = len(r.TransferEncoding) > 0 && r.TransferEncoding[0] == "chunked"
|
|
1737
|
+
req.rawH2 = hs.h2 && r.ProtoMajor == 2
|
|
1738
|
+
req.rawTLS = r.TLS != nil
|
|
1739
|
+
req.rawLocal = local
|
|
1740
|
+
req.rawRemote = r.RemoteAddr
|
|
671
1741
|
return req
|
|
672
1742
|
}
|
|
673
1743
|
|
|
@@ -733,22 +1803,22 @@ func (hs *TnHttpServer) serveUpgrade(w http.ResponseWriter, r *http.Request, loc
|
|
|
733
1803
|
}
|
|
734
1804
|
|
|
735
1805
|
// HTTP/2 requests carry :method / :scheme / :authority / :path first, as in Node
|
|
736
|
-
func tnPseudoHeaders(req *TnIncomingMessage
|
|
1806
|
+
func tnPseudoHeaders(req *TnIncomingMessage) {
|
|
737
1807
|
scheme := "http"
|
|
738
|
-
if
|
|
1808
|
+
if req.rawTLS {
|
|
739
1809
|
scheme = "https"
|
|
740
1810
|
}
|
|
741
1811
|
headers := TnNewMap[string, string]()
|
|
742
|
-
headers.Set(":method",
|
|
1812
|
+
headers.Set(":method", req.method)
|
|
743
1813
|
headers.Set(":scheme", scheme)
|
|
744
|
-
headers.Set(":authority",
|
|
745
|
-
headers.Set(":path",
|
|
746
|
-
for k, v := range req.
|
|
1814
|
+
headers.Set(":authority", req.rawHost)
|
|
1815
|
+
headers.Set(":path", req.url)
|
|
1816
|
+
for k, v := range req.hdrs.All() {
|
|
747
1817
|
if k != "host" {
|
|
748
1818
|
headers.Set(k, v)
|
|
749
1819
|
}
|
|
750
1820
|
}
|
|
751
|
-
req.
|
|
1821
|
+
req.hdrs = headers
|
|
752
1822
|
}
|
|
753
1823
|
|
|
754
1824
|
// Applies a response's queued operations on the handler goroutine until it ends
|
|
@@ -795,7 +1865,7 @@ func tnServeOps(w http.ResponseWriter, r *http.Request, res *TnServerResponse, a
|
|
|
795
1865
|
break
|
|
796
1866
|
}
|
|
797
1867
|
select {
|
|
798
|
-
case <-res.
|
|
1868
|
+
case <-res.sig():
|
|
799
1869
|
case <-r.Context().Done():
|
|
800
1870
|
TnLoopPost(abort)
|
|
801
1871
|
<-bodyDone
|
|
@@ -806,7 +1876,7 @@ func tnServeOps(w http.ResponseWriter, r *http.Request, res *TnServerResponse, a
|
|
|
806
1876
|
}
|
|
807
1877
|
|
|
808
1878
|
func TnNewHttpServer(secure bool, args ...interface{}) *TnHttpServer {
|
|
809
|
-
hs := &TnHttpServer{keepAliveTimeout: 5000, headersTimeout: 60000, requestTimeout: 300000}
|
|
1879
|
+
hs := &TnHttpServer{keepAliveTimeout: 5000, headersTimeout: 60000, requestTimeout: 300000, httpConns: map[*tnHttpConn]struct{}{}}
|
|
810
1880
|
hs.TnNetServer = *TnNewNetServer()
|
|
811
1881
|
hs.connectionEvent = "connection"
|
|
812
1882
|
for _, a := range args {
|
|
@@ -825,8 +1895,29 @@ func TnNewHttpServer(secure bool, args ...interface{}) *TnHttpServer {
|
|
|
825
1895
|
if hs.tlsConfig != nil {
|
|
826
1896
|
ln = tls.NewListener(ln, hs.tlsConfig)
|
|
827
1897
|
}
|
|
828
|
-
|
|
829
|
-
|
|
1898
|
+
if hs.h2 {
|
|
1899
|
+
hs.httpServer.IdleTimeout = time.Duration(hs.keepAliveTimeout * float64(time.Millisecond))
|
|
1900
|
+
hs.httpServer.Serve(ln)
|
|
1901
|
+
return
|
|
1902
|
+
}
|
|
1903
|
+
local := ln.Addr()
|
|
1904
|
+
for {
|
|
1905
|
+
conn, err := ln.Accept()
|
|
1906
|
+
if err != nil {
|
|
1907
|
+
return
|
|
1908
|
+
}
|
|
1909
|
+
hc := &tnHttpConn{conn: conn, closed: make(chan struct{})}
|
|
1910
|
+
hs.connMu.Lock()
|
|
1911
|
+
if atomic.LoadInt32(&hs.closing) != 0 {
|
|
1912
|
+
hs.connMu.Unlock()
|
|
1913
|
+
conn.Close()
|
|
1914
|
+
return
|
|
1915
|
+
}
|
|
1916
|
+
hs.httpConns[hc] = struct{}{}
|
|
1917
|
+
hs.inFlight.Add(1)
|
|
1918
|
+
hs.connMu.Unlock()
|
|
1919
|
+
go hs.serveConn(hc, local)
|
|
1920
|
+
}
|
|
830
1921
|
}
|
|
831
1922
|
return hs
|
|
832
1923
|
}
|
|
@@ -845,13 +1936,22 @@ func (hs *TnHttpServer) close(cb ...interface{}) *TnHttpServer {
|
|
|
845
1936
|
if hs.ln == nil {
|
|
846
1937
|
return hs
|
|
847
1938
|
}
|
|
1939
|
+
hs.connMu.Lock()
|
|
1940
|
+
atomic.StoreInt32(&hs.closing, 1)
|
|
1941
|
+
hs.connMu.Unlock()
|
|
848
1942
|
// Closing the listener first also covers a Serve that has not started yet
|
|
849
1943
|
hs.ln.Close()
|
|
850
1944
|
hs.ln = nil
|
|
851
1945
|
hs.listening = false
|
|
1946
|
+
hs.closeIdleConnections()
|
|
852
1947
|
TnLoopRef()
|
|
853
1948
|
go func() {
|
|
854
|
-
hs.
|
|
1949
|
+
if hs.h2 {
|
|
1950
|
+
hs.httpServer.Shutdown(context.Background())
|
|
1951
|
+
} else {
|
|
1952
|
+
hs.inFlight.Wait()
|
|
1953
|
+
hs.closeAllConnections()
|
|
1954
|
+
}
|
|
855
1955
|
TnLoopPost(func() {
|
|
856
1956
|
defer TnLoopUnref()
|
|
857
1957
|
if hs.refd {
|
|
@@ -865,15 +1965,37 @@ func (hs *TnHttpServer) close(cb ...interface{}) *TnHttpServer {
|
|
|
865
1965
|
}
|
|
866
1966
|
|
|
867
1967
|
func (hs *TnHttpServer) closeAllConnections() {
|
|
868
|
-
if hs.httpServer != nil {
|
|
1968
|
+
if hs.h2 && hs.httpServer != nil {
|
|
869
1969
|
hs.httpServer.Close()
|
|
1970
|
+
return
|
|
1971
|
+
}
|
|
1972
|
+
hs.connMu.Lock()
|
|
1973
|
+
conns := make([]*tnHttpConn, 0, len(hs.httpConns))
|
|
1974
|
+
for hc := range hs.httpConns {
|
|
1975
|
+
conns = append(conns, hc)
|
|
1976
|
+
}
|
|
1977
|
+
hs.connMu.Unlock()
|
|
1978
|
+
for _, hc := range conns {
|
|
1979
|
+
hc.closeConn()
|
|
870
1980
|
}
|
|
871
1981
|
}
|
|
872
1982
|
|
|
873
1983
|
func (hs *TnHttpServer) closeIdleConnections() {
|
|
874
|
-
if hs.httpServer != nil {
|
|
1984
|
+
if hs.h2 && hs.httpServer != nil {
|
|
875
1985
|
hs.httpServer.SetKeepAlivesEnabled(false)
|
|
876
1986
|
hs.httpServer.SetKeepAlivesEnabled(true)
|
|
1987
|
+
return
|
|
1988
|
+
}
|
|
1989
|
+
hs.connMu.Lock()
|
|
1990
|
+
var idle []*tnHttpConn
|
|
1991
|
+
for hc := range hs.httpConns {
|
|
1992
|
+
if atomic.LoadInt32(&hc.active) == 0 {
|
|
1993
|
+
idle = append(idle, hc)
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
hs.connMu.Unlock()
|
|
1997
|
+
for _, hc := range idle {
|
|
1998
|
+
hc.closeConn()
|
|
877
1999
|
}
|
|
878
2000
|
}
|
|
879
2001
|
|
|
@@ -929,7 +2051,7 @@ type TnClientRequest struct {
|
|
|
929
2051
|
host string
|
|
930
2052
|
protocol string
|
|
931
2053
|
port string
|
|
932
|
-
store
|
|
2054
|
+
store tnHeaderStore
|
|
933
2055
|
started bool
|
|
934
2056
|
aborted bool
|
|
935
2057
|
gotResponse bool
|
|
@@ -1282,8 +2404,8 @@ func (cr *TnClientRequest) start(body []byte, complete bool) {
|
|
|
1282
2404
|
res.httpVersionMajor, res.httpVersionMinor = float64(resp.ProtoMajor), float64(resp.ProtoMinor)
|
|
1283
2405
|
chunked := len(resp.TransferEncoding) > 0 && resp.TransferEncoding[0] == "chunked"
|
|
1284
2406
|
tnIncomingHeaders(res, resp.Header, "", chunked)
|
|
1285
|
-
if resp.ContentLength >= 0 && !res.
|
|
1286
|
-
res.
|
|
2407
|
+
if resp.ContentLength >= 0 && !res.Get_headers().Has("content-length") && cr.method != "HEAD" {
|
|
2408
|
+
res.Get_headers().Set("content-length", strconv.FormatInt(resp.ContentLength, 10))
|
|
1287
2409
|
}
|
|
1288
2410
|
res.socket = tnInfoSocket(nil, net.JoinHostPort(host, port))
|
|
1289
2411
|
if resp.TLS != nil {
|
|
@@ -1314,7 +2436,7 @@ func (cr *TnClientRequest) start(body []byte, complete bool) {
|
|
|
1314
2436
|
// The trailers are read with the end of the body, before 'end'
|
|
1315
2437
|
tnPumpBody(resp.Body, res, func() {
|
|
1316
2438
|
for k, v := range resp.Trailer {
|
|
1317
|
-
res.
|
|
2439
|
+
res.Get_trailers().Set(strings.ToLower(k), strings.Join(v, ", "))
|
|
1318
2440
|
}
|
|
1319
2441
|
}, func() {
|
|
1320
2442
|
TnLoopPost(func() {
|
|
@@ -1355,11 +2477,14 @@ func tnClientURL(cr *TnClientRequest, raw string) {
|
|
|
1355
2477
|
|
|
1356
2478
|
// http.request(url | options, [options], [callback]) / https.request
|
|
1357
2479
|
func TnHttpRequest(secure bool, args ...interface{}) *TnClientRequest {
|
|
1358
|
-
cr := &TnClientRequest{method: "GET", path: "/", host: "localhost", protocol: "http:",
|
|
2480
|
+
cr := &TnClientRequest{method: "GET", path: "/", host: "localhost", protocol: "http:", setHost: true}
|
|
1359
2481
|
if secure {
|
|
1360
2482
|
cr.protocol = "https:"
|
|
1361
2483
|
}
|
|
1362
|
-
cr.
|
|
2484
|
+
cr.flowing = -1
|
|
2485
|
+
cr.decodeStrings = true
|
|
2486
|
+
cr.writableSide = true
|
|
2487
|
+
cr.asyncCtx = TnAsyncSnapshot()
|
|
1363
2488
|
cr.tnSelf = cr
|
|
1364
2489
|
cr.closeHeld = true
|
|
1365
2490
|
var options interface{}
|
|
@@ -1503,9 +2628,9 @@ function eventName(nodes) {
|
|
|
1503
2628
|
export function registerHttp(r) {
|
|
1504
2629
|
defineModule(r, 'http');
|
|
1505
2630
|
defineModule(r, 'https');
|
|
1506
|
-
defineHelper(r, 'nodeHttp', ['bufio', 'bytes', 'context', 'crypto/tls', 'errors', 'fmt', 'io', 'log', 'math', 'net', 'net/http', 'net/url', 'reflect', 'sort', 'strconv', 'strings', 'sync', 'time', 'unsafe'], ['nodeNet', 'netErrors', 'nodeStream', 'nodeEvents', 'eventLoop', 'nodeInvoke', 'dynamic', 'orderedMap', 'buffer', 'tlsConfig'], httpHelper);
|
|
2631
|
+
defineHelper(r, 'nodeHttp', ['bufio', 'bytes', 'context', 'crypto/tls', 'errors', 'fmt', 'io', 'log', 'math', 'net', 'net/http', 'net/url', 'reflect', 'sort', 'strconv', 'strings', 'sync', 'sync/atomic', 'time', 'unsafe'], ['nodeNet', 'netErrors', 'nodeStream', 'nodeEvents', 'eventLoop', 'nodeInvoke', 'dynamic', 'orderedMap', 'buffer', 'tlsConfig'], httpHelper);
|
|
1507
2632
|
const use = () => r.helper('nodeHttp');
|
|
1508
|
-
defineClass(r, 'http.IncomingMessage', '*TnIncomingMessage', 'class', STREAM_METHODS + '; setTimeout=*TnIncomingMessage', 'method=string; url=string; httpVersion=string; httpVersionMajor=float64; httpVersionMinor=float64; headers=*TnMap[string, string]; headersDistinct=*TnMap[string, []string]; rawHeaders=[]string; trailers=*TnMap[string, string];
|
|
2633
|
+
defineClass(r, 'http.IncomingMessage', '*TnIncomingMessage', 'class', STREAM_METHODS + '; setTimeout=*TnIncomingMessage', 'method=string; url=string; httpVersion=string; httpVersionMajor=float64; httpVersionMinor=float64; statusCode=float64; statusMessage=string; complete=bool; aborted=bool', STREAM_GETTERS + '; headers=*TnMap[string, string]; headersDistinct=*TnMap[string, []string]; rawHeaders=[]string; trailers=*TnMap[string, string]; socket=*TnSocket; connection=*TnSocket', '');
|
|
1509
2634
|
defineClass(r, 'http.ServerResponse', '*TnServerResponse', 'class', SERVER_RESPONSE_METHODS, 'statusCode=float64; statusMessage=string; sendDate=bool', STREAM_GETTERS + '; headersSent=bool; req=*TnIncomingMessage; socket=*TnSocket', '');
|
|
1510
2635
|
defineClass(r, 'http.ClientRequest', '*TnClientRequest', 'class', CLIENT_REQUEST_METHODS, 'method=string; path=string; host=string; protocol=string; aborted=bool; reusedSocket=bool; maxHeadersCount=interface{}', STREAM_GETTERS + '; headersSent=bool; socket=*TnSocket', '');
|
|
1511
2636
|
defineClass(r, 'http.Server', '*TnHttpServer', 'class', SERVER_METHODS.replace('listen=*TnNetServer', 'listen=*TnHttpServer').replace('close=*TnNetServer', 'close=*TnHttpServer') +
|
|
@@ -1521,6 +2646,19 @@ export function registerHttp(r) {
|
|
|
1521
2646
|
};
|
|
1522
2647
|
r.typers[`http.${cls}#pipe`] = (c) => c.types[0] || '*TnStream';
|
|
1523
2648
|
}
|
|
2649
|
+
r.methods['http.ServerResponse#writeHead'] = (c) => {
|
|
2650
|
+
if (c.nodes.length === 2 && isObjectLiteral(c.nodes[1])) {
|
|
2651
|
+
const props = c.nodes[1].properties ?? [];
|
|
2652
|
+
if (props.length === 1 && props[0].kind === 'PropertyAssignment' && props[0].name && isStringNode(props[0].initializer)) {
|
|
2653
|
+
const k = props[0].name.kind === 'Identifier' || props[0].name.kind === 'StringLiteral' ? String(props[0].name.text) : '';
|
|
2654
|
+
if (k !== '') {
|
|
2655
|
+
return `${c.recv}.writeHeadKV(${c.args[0]}, ${goString(k)}, ${goString(String(props[0].initializer.text))})`;
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
return `${c.recv}.writeHead(${c.args.join(', ')})`;
|
|
2660
|
+
};
|
|
2661
|
+
r.methods['https.ServerResponse#writeHead'] = r.methods['http.ServerResponse#writeHead'];
|
|
1524
2662
|
r.paramTypers['http.IncomingMessage#on'] = streamListenerTypes;
|
|
1525
2663
|
r.paramTypers['http.IncomingMessage#once'] = streamListenerTypes;
|
|
1526
2664
|
r.paramTypers['http.ServerResponse#on'] = streamListenerTypes;
|