File tree Expand file tree Collapse file tree 2 files changed +42
-3
lines changed Expand file tree Collapse file tree 2 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -621,7 +621,28 @@ class Parser : public AsyncWrap {
621
621
size_t nparsed =
622
622
http_parser_execute (&parser_, &settings, data, len);
623
623
624
- Save ();
624
+ enum http_errno err = HTTP_PARSER_ERRNO (&parser_);
625
+
626
+ // Finish()
627
+ if (data == nullptr ) {
628
+ // `http_parser_execute()` returns either `0` or `1` when `len` is 0
629
+ // (part of the finishing sequence).
630
+ CHECK_EQ (len, 0 );
631
+ switch (nparsed) {
632
+ case 0 :
633
+ err = HPE_OK;
634
+ break ;
635
+ case 1 :
636
+ nparsed = 0 ;
637
+ break ;
638
+ default :
639
+ UNREACHABLE ();
640
+ }
641
+
642
+ // Regular Execute()
643
+ } else {
644
+ Save ();
645
+ }
625
646
626
647
// Unassign the 'buffer_' variable
627
648
current_buffer_.Clear ();
@@ -635,7 +656,7 @@ class Parser : public AsyncWrap {
635
656
Local<Integer> nparsed_obj = Integer::New (env ()->isolate (), nparsed);
636
657
// If there was a parse error in one of the callbacks
637
658
// TODO(bnoordhuis) What if there is an error on EOF?
638
- if (!parser_.upgrade && nparsed != len ) {
659
+ if (!parser_.upgrade && err != HPE_OK ) {
639
660
enum http_errno err = HTTP_PARSER_ERRNO (&parser_);
640
661
641
662
Local<Value> e = Exception::Error (env ()->parse_error_string ());
@@ -646,6 +667,11 @@ class Parser : public AsyncWrap {
646
667
647
668
return scope.Escape (e);
648
669
}
670
+
671
+ // No return value is needed for `Finish()`
672
+ if (data == nullptr ) {
673
+ return scope.Escape (Local<Value>());
674
+ }
649
675
return scope.Escape (nparsed_obj);
650
676
}
651
677
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