@@ -27,7 +27,6 @@ const binding = process.binding('http_parser');
27
27
const methods = binding . methods ;
28
28
const HTTPParser = binding . HTTPParser ;
29
29
30
- const CRLF = '\r\n' ;
31
30
const REQUEST = HTTPParser . REQUEST ;
32
31
const RESPONSE = HTTPParser . RESPONSE ;
33
32
@@ -92,7 +91,7 @@ function expectBody(expected) {
92
91
// Simple request test.
93
92
//
94
93
{
95
- const request = Buffer . from ( ` GET /hello HTTP/1.1${ CRLF } ${ CRLF } ` ) ;
94
+ const request = Buffer . from ( ' GET /hello HTTP/1.1\r\n\r\n' ) ;
96
95
97
96
const onHeadersComplete = ( versionMajor , versionMinor , headers ,
98
97
method , url , statusCode , statusMessage ,
@@ -129,11 +128,12 @@ function expectBody(expected) {
129
128
//
130
129
{
131
130
const request = Buffer . from (
132
- 'HTTP/1.1 200 OK' + CRLF +
133
- 'Content-Type: text/plain' + CRLF +
134
- 'Content-Length: 4' + CRLF +
135
- CRLF +
136
- 'pong' ) ;
131
+ 'HTTP/1.1 200 OK\r\n' +
132
+ 'Content-Type: text/plain\r\n' +
133
+ 'Content-Length: 4\r\n' +
134
+ '\r\n' +
135
+ 'pong'
136
+ ) ;
137
137
138
138
const onHeadersComplete = ( versionMajor , versionMinor , headers ,
139
139
method , url , statusCode , statusMessage ,
@@ -162,7 +162,7 @@ function expectBody(expected) {
162
162
//
163
163
{
164
164
const request = Buffer . from (
165
- ` HTTP/1.0 200 Connection established${ CRLF } ${ CRLF } ` ) ;
165
+ ' HTTP/1.0 200 Connection established\r\n\r\n' ) ;
166
166
167
167
const onHeadersComplete = ( versionMajor , versionMinor , headers ,
168
168
method , url , statusCode , statusMessage ,
@@ -186,15 +186,16 @@ function expectBody(expected) {
186
186
//
187
187
{
188
188
const request = Buffer . from (
189
- 'POST /it HTTP/1.1' + CRLF +
190
- 'Transfer-Encoding: chunked' + CRLF +
191
- CRLF +
192
- '4' + CRLF +
193
- 'ping' + CRLF +
194
- '0' + CRLF +
195
- 'Vary: *' + CRLF +
196
- 'Content-Type: text/plain' + CRLF +
197
- CRLF ) ;
189
+ 'POST /it HTTP/1.1\r\n' +
190
+ 'Transfer-Encoding: chunked\r\n' +
191
+ '\r\n' +
192
+ '4\r\n' +
193
+ 'ping\r\n' +
194
+ '0\r\n' +
195
+ 'Vary: *\r\n' +
196
+ 'Content-Type: text/plain\r\n' +
197
+ '\r\n'
198
+ ) ;
198
199
199
200
let seen_body = false ;
200
201
@@ -233,11 +234,12 @@ function expectBody(expected) {
233
234
//
234
235
{
235
236
const request = Buffer . from (
236
- 'GET / HTTP/1.0' + CRLF +
237
- 'X-Filler: 1337' + CRLF +
238
- 'X-Filler: 42' + CRLF +
239
- 'X-Filler2: 42' + CRLF +
240
- CRLF ) ;
237
+ 'GET / HTTP/1.0\r\n' +
238
+ 'X-Filler: 1337\r\n' +
239
+ 'X-Filler: 42\r\n' +
240
+ 'X-Filler2: 42\r\n' +
241
+ '\r\n'
242
+ ) ;
241
243
242
244
const onHeadersComplete = ( versionMajor , versionMinor , headers ,
243
245
method , url , statusCode , statusMessage ,
@@ -246,8 +248,8 @@ function expectBody(expected) {
246
248
assert . strictEqual ( versionMajor , 1 ) ;
247
249
assert . strictEqual ( versionMinor , 0 ) ;
248
250
assert . deepStrictEqual (
249
- headers || parser . headers ,
250
- [ 'X-Filler' , '1337' , 'X-Filler' , '42' , 'X-Filler2' , '42' ] ) ;
251
+ headers || parser . headers ,
252
+ [ 'X-Filler' , '1337' , 'X-Filler' , '42' , 'X-Filler2' , '42' ] ) ;
251
253
} ;
252
254
253
255
const parser = newParser ( REQUEST ) ;
@@ -261,12 +263,13 @@ function expectBody(expected) {
261
263
//
262
264
{
263
265
// 256 X-Filler headers
264
- const lots_of_headers = ` X-Filler: 42${ CRLF } ` . repeat ( 256 ) ;
266
+ const lots_of_headers = ' X-Filler: 42\r\n' . repeat ( 256 ) ;
265
267
266
268
const request = Buffer . from (
267
- 'GET /foo/bar/baz?quux=42#1337 HTTP/1.0' + CRLF +
268
- lots_of_headers +
269
- CRLF ) ;
269
+ 'GET /foo/bar/baz?quux=42#1337 HTTP/1.0\r\n' +
270
+ lots_of_headers +
271
+ '\r\n'
272
+ ) ;
270
273
271
274
const onHeadersComplete = ( versionMajor , versionMinor , headers ,
272
275
method , url , statusCode , statusMessage ,
@@ -296,11 +299,12 @@ function expectBody(expected) {
296
299
//
297
300
{
298
301
const request = Buffer . from (
299
- 'POST /it HTTP/1.1' + CRLF +
300
- 'Content-Type: application/x-www-form-urlencoded' + CRLF +
301
- 'Content-Length: 15' + CRLF +
302
- CRLF +
303
- 'foo=42&bar=1337' ) ;
302
+ 'POST /it HTTP/1.1\r\n' +
303
+ 'Content-Type: application/x-www-form-urlencoded\r\n' +
304
+ 'Content-Length: 15\r\n' +
305
+ '\r\n' +
306
+ 'foo=42&bar=1337'
307
+ ) ;
304
308
305
309
const onHeadersComplete = ( versionMajor , versionMinor , headers ,
306
310
method , url , statusCode , statusMessage ,
@@ -328,17 +332,18 @@ function expectBody(expected) {
328
332
//
329
333
{
330
334
const request = Buffer . from (
331
- 'POST /it HTTP/1.1' + CRLF +
332
- 'Content-Type: text/plain' + CRLF +
333
- 'Transfer-Encoding: chunked' + CRLF +
334
- CRLF +
335
- '3' + CRLF +
336
- '123' + CRLF +
337
- '6' + CRLF +
338
- '123456' + CRLF +
339
- 'A' + CRLF +
340
- '1234567890' + CRLF +
341
- '0' + CRLF ) ;
335
+ 'POST /it HTTP/1.1\r\n' +
336
+ 'Content-Type: text/plain\r\n' +
337
+ 'Transfer-Encoding: chunked\r\n' +
338
+ '\r\n' +
339
+ '3\r\n' +
340
+ '123\r\n' +
341
+ '6\r\n' +
342
+ '123456\r\n' +
343
+ 'A\r\n' +
344
+ '1234567890\r\n' +
345
+ '0\r\n'
346
+ ) ;
342
347
343
348
const onHeadersComplete = ( versionMajor , versionMinor , headers ,
344
349
method , url , statusCode , statusMessage ,
@@ -369,14 +374,15 @@ function expectBody(expected) {
369
374
//
370
375
{
371
376
let request = Buffer . from (
372
- 'POST /it HTTP/1.1' + CRLF +
373
- 'Content-Type: text/plain' + CRLF +
374
- 'Transfer-Encoding: chunked' + CRLF +
375
- CRLF +
376
- '3' + CRLF +
377
- '123' + CRLF +
378
- '6' + CRLF +
379
- '123456' + CRLF ) ;
377
+ 'POST /it HTTP/1.1\r\n' +
378
+ 'Content-Type: text/plain\r\n' +
379
+ 'Transfer-Encoding: chunked\r\n' +
380
+ '\r\n' +
381
+ '3\r\n' +
382
+ '123\r\n' +
383
+ '6\r\n' +
384
+ '123456\r\n'
385
+ ) ;
380
386
381
387
const onHeadersComplete = ( versionMajor , versionMinor , headers ,
382
388
method , url , statusCode , statusMessage ,
@@ -402,13 +408,14 @@ function expectBody(expected) {
402
408
parser . execute ( request , 0 , request . length ) ;
403
409
404
410
request = Buffer . from (
405
- '9' + CRLF +
406
- '123456789' + CRLF +
407
- 'C' + CRLF +
408
- '123456789ABC' + CRLF +
409
- 'F' + CRLF +
410
- '123456789ABCDEF' + CRLF +
411
- '0' + CRLF ) ;
411
+ '9\r\n' +
412
+ '123456789\r\n' +
413
+ 'C\r\n' +
414
+ '123456789ABC\r\n' +
415
+ 'F\r\n' +
416
+ '123456789ABCDEF\r\n' +
417
+ '0\r\n'
418
+ ) ;
412
419
413
420
parser . execute ( request , 0 , request . length ) ;
414
421
}
@@ -419,21 +426,22 @@ function expectBody(expected) {
419
426
//
420
427
{
421
428
const request = Buffer . from (
422
- 'POST /helpme HTTP/1.1' + CRLF +
423
- 'Content-Type: text/plain' + CRLF +
424
- 'Transfer-Encoding: chunked' + CRLF +
425
- CRLF +
426
- '3' + CRLF +
427
- '123' + CRLF +
428
- '6' + CRLF +
429
- '123456' + CRLF +
430
- '9' + CRLF +
431
- '123456789' + CRLF +
432
- 'C' + CRLF +
433
- '123456789ABC' + CRLF +
434
- 'F' + CRLF +
435
- '123456789ABCDEF' + CRLF +
436
- '0' + CRLF ) ;
429
+ 'POST /helpme HTTP/1.1\r\n' +
430
+ 'Content-Type: text/plain\r\n' +
431
+ 'Transfer-Encoding: chunked\r\n' +
432
+ '\r\n' +
433
+ '3\r\n' +
434
+ '123\r\n' +
435
+ '6\r\n' +
436
+ '123456\r\n' +
437
+ '9\r\n' +
438
+ '123456789\r\n' +
439
+ 'C\r\n' +
440
+ '123456789ABC\r\n' +
441
+ 'F\r\n' +
442
+ '123456789ABCDEF\r\n' +
443
+ '0\r\n'
444
+ ) ;
437
445
438
446
function test ( a , b ) {
439
447
const onHeadersComplete = ( versionMajor , versionMinor , headers ,
@@ -477,21 +485,22 @@ function expectBody(expected) {
477
485
//
478
486
{
479
487
const request = Buffer . from (
480
- 'POST /it HTTP/1.1' + CRLF +
481
- 'Content-Type: text/plain' + CRLF +
482
- 'Transfer-Encoding: chunked' + CRLF +
483
- CRLF +
484
- '3' + CRLF +
485
- '123' + CRLF +
486
- '6' + CRLF +
487
- '123456' + CRLF +
488
- '9' + CRLF +
489
- '123456789' + CRLF +
490
- 'C' + CRLF +
491
- '123456789ABC' + CRLF +
492
- 'F' + CRLF +
493
- '123456789ABCDEF' + CRLF +
494
- '0' + CRLF ) ;
488
+ 'POST /it HTTP/1.1\r\n' +
489
+ 'Content-Type: text/plain\r\n' +
490
+ 'Transfer-Encoding: chunked\r\n' +
491
+ '\r\n' +
492
+ '3\r\n' +
493
+ '123\r\n' +
494
+ '6\r\n' +
495
+ '123456\r\n' +
496
+ '9\r\n' +
497
+ '123456789\r\n' +
498
+ 'C\r\n' +
499
+ '123456789ABC\r\n' +
500
+ 'F\r\n' +
501
+ '123456789ABCDEF\r\n' +
502
+ '0\r\n'
503
+ ) ;
495
504
496
505
const onHeadersComplete = ( versionMajor , versionMinor , headers ,
497
506
method , url , statusCode , statusMessage ,
@@ -501,8 +510,8 @@ function expectBody(expected) {
501
510
assert . strictEqual ( versionMajor , 1 ) ;
502
511
assert . strictEqual ( versionMinor , 1 ) ;
503
512
assert . deepStrictEqual (
504
- headers || parser . headers ,
505
- [ 'Content-Type' , 'text/plain' , 'Transfer-Encoding' , 'chunked' ] ) ;
513
+ headers || parser . headers ,
514
+ [ 'Content-Type' , 'text/plain' , 'Transfer-Encoding' , 'chunked' ] ) ;
506
515
} ;
507
516
508
517
let expected_body = '123123456123456789123456789ABC123456789ABCDEF' ;
@@ -530,20 +539,22 @@ function expectBody(expected) {
530
539
//
531
540
{
532
541
const req1 = Buffer . from (
533
- 'PUT /this HTTP/1.1' + CRLF +
534
- 'Content-Type: text/plain' + CRLF +
535
- 'Transfer-Encoding: chunked' + CRLF +
536
- CRLF +
537
- '4' + CRLF +
538
- 'ping' + CRLF +
539
- '0' + CRLF ) ;
542
+ 'PUT /this HTTP/1.1\r\n' +
543
+ 'Content-Type: text/plain\r\n' +
544
+ 'Transfer-Encoding: chunked\r\n' +
545
+ '\r\n' +
546
+ '4\r\n' +
547
+ 'ping\r\n' +
548
+ '0\r\n'
549
+ ) ;
540
550
541
551
const req2 = Buffer . from (
542
- 'POST /that HTTP/1.0' + CRLF +
543
- 'Content-Type: text/plain' + CRLF +
544
- 'Content-Length: 4' + CRLF +
545
- CRLF +
546
- 'pong' ) ;
552
+ 'POST /that HTTP/1.0\r\n' +
553
+ 'Content-Type: text/plain\r\n' +
554
+ 'Content-Length: 4\r\n' +
555
+ '\r\n' +
556
+ 'pong'
557
+ ) ;
547
558
548
559
const onHeadersComplete1 = ( versionMajor , versionMinor , headers ,
549
560
method , url , statusCode , statusMessage ,
@@ -553,8 +564,8 @@ function expectBody(expected) {
553
564
assert . strictEqual ( versionMajor , 1 ) ;
554
565
assert . strictEqual ( versionMinor , 1 ) ;
555
566
assert . deepStrictEqual (
556
- headers ,
557
- [ 'Content-Type' , 'text/plain' , 'Transfer-Encoding' , 'chunked' ] ) ;
567
+ headers ,
568
+ [ 'Content-Type' , 'text/plain' , 'Transfer-Encoding' , 'chunked' ] ) ;
558
569
} ;
559
570
560
571
const onHeadersComplete2 = ( versionMajor , versionMinor , headers ,
@@ -584,7 +595,7 @@ function expectBody(expected) {
584
595
// Test parser 'this' safety
585
596
// https://github.com/joyent/node/issues/6690
586
597
assert . throws ( function ( ) {
587
- const request = Buffer . from ( ` GET /hello HTTP/1.1${ CRLF } ${ CRLF } ` ) ;
598
+ const request = Buffer . from ( ' GET /hello HTTP/1.1\r\n\r\n' ) ;
588
599
589
600
const parser = newParser ( REQUEST ) ;
590
601
const notparser = { execute : parser . execute } ;
0 commit comments