File tree 2 files changed +42
-3
lines changed
2 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -610,7 +610,28 @@ class Parser : public AsyncWrap {
610
610
size_t nparsed =
611
611
http_parser_execute (&parser_, &settings, data, len);
612
612
613
- Save ();
613
+ enum http_errno err = HTTP_PARSER_ERRNO (&parser_);
614
+
615
+ // Finish()
616
+ if (data == nullptr ) {
617
+ // `http_parser_execute()` returns either `0` or `1` when `len` is 0
618
+ // (part of the finishing sequence).
619
+ CHECK_EQ (len, 0 );
620
+ switch (nparsed) {
621
+ case 0 :
622
+ err = HPE_OK;
623
+ break ;
624
+ case 1 :
625
+ nparsed = 0 ;
626
+ break ;
627
+ default :
628
+ UNREACHABLE ();
629
+ }
630
+
631
+ // Regular Execute()
632
+ } else {
633
+ Save ();
634
+ }
614
635
615
636
// Unassign the 'buffer_' variable
616
637
current_buffer_.Clear ();
@@ -624,7 +645,7 @@ class Parser : public AsyncWrap {
624
645
Local<Integer> nparsed_obj = Integer::New (env ()->isolate (), nparsed);
625
646
// If there was a parse error in one of the callbacks
626
647
// TODO(bnoordhuis) What if there is an error on EOF?
627
- if (!parser_.upgrade && nparsed != len ) {
648
+ if (!parser_.upgrade && err != HPE_OK ) {
628
649
enum http_errno err = HTTP_PARSER_ERRNO (&parser_);
629
650
630
651
Local<Value> e = Exception::Error (env ()->parse_error_string ());
@@ -635,6 +656,11 @@ class Parser : public AsyncWrap {
635
656
636
657
return scope.Escape (e);
637
658
}
659
+
660
+ // No return value is needed for `Finish()`
661
+ if (data == nullptr ) {
662
+ return scope.Escape (Local<Value>());
663
+ }
638
664
return scope.Escape (nparsed_obj);
639
665
}
640
666
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
- require ( '../common' ) ;
3
+ const common = require ( '../common' ) ;
4
4
const assert = require ( 'assert' ) ;
5
5
const { spawnSync } = require ( 'child_process' ) ;
6
6
const http = require ( 'http' ) ;
@@ -9,3 +9,16 @@ assert.strictEqual(http.maxHeaderSize, 8 * 1024);
9
9
const child = spawnSync ( process . execPath , [ '--max-http-header-size=10' , '-p' ,
10
10
'http.maxHeaderSize' ] ) ;
11
11
assert . strictEqual ( + child . stdout . toString ( ) . trim ( ) , 10 ) ;
12
+
13
+ {
14
+ const server = http . createServer ( common . mustNotCall ( ) ) ;
15
+ server . listen ( 0 , common . mustCall ( ( ) => {
16
+ http . get ( {
17
+ port : server . address ( ) . port ,
18
+ headers : { foo : 'x' . repeat ( http . maxHeaderSize + 1 ) }
19
+ } , common . mustNotCall ( ) ) . once ( 'error' , common . mustCall ( ( err ) => {
20
+ assert . strictEqual ( err . code , 'ECONNRESET' ) ;
21
+ server . close ( ) ;
22
+ } ) ) ;
23
+ } ) ) ;
24
+ }
You can’t perform that action at this time.
0 commit comments