File tree 3 files changed +34
-3
lines changed
3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -1074,8 +1074,8 @@ type other than {net.Socket}.
1074
1074
1075
1075
Default behavior is to try close the socket with a HTTP '400 Bad Request',
1076
1076
or a HTTP '431 Request Header Fields Too Large' in the case of a
1077
- [ ` HPE_HEADER_OVERFLOW ` ] [ ] error. If the socket is not writable it is
1078
- immediately destroyed.
1077
+ [ ` HPE_HEADER_OVERFLOW ` ] [ ] error. If the socket is not writable or has already
1078
+ written data it is immediately destroyed.
1079
1079
1080
1080
` socket ` is the [ ` net.Socket ` ] [ ] object that the error originated from.
1081
1081
Original file line number Diff line number Diff line change @@ -618,7 +618,7 @@ function socketOnError(e) {
618
618
this . on ( 'error' , noop ) ;
619
619
620
620
if ( ! this . server . emit ( 'clientError' , e , this ) ) {
621
- if ( this . writable ) {
621
+ if ( this . writable && this . bytesWritten === 0 ) {
622
622
const response = e . code === 'HPE_HEADER_OVERFLOW' ?
623
623
requestHeaderFieldsTooLargeResponse : badRequestResponse ;
624
624
this . write ( response ) ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+ const { mustCall } = require ( '../common' ) ;
3
+ const assert = require ( 'assert' ) ;
4
+ const { createServer } = require ( 'http' ) ;
5
+ const { createConnection } = require ( 'net' ) ;
6
+
7
+ const server = createServer ( ) ;
8
+
9
+ server . on ( 'request' , mustCall ( ( req , res ) => {
10
+ res . write ( 'asd' , ( ) => {
11
+ res . socket . emit ( 'error' , new Error ( 'kaboom' ) ) ;
12
+ } ) ;
13
+ } ) ) ;
14
+
15
+ server . listen ( 0 , mustCall ( ( ) => {
16
+ const c = createConnection ( server . address ( ) . port ) ;
17
+ let received = '' ;
18
+
19
+ c . on ( 'connect' , mustCall ( ( ) => {
20
+ c . write ( 'GET /blah HTTP/1.1\r\n\r\n' ) ;
21
+ } ) ) ;
22
+ c . on ( 'data' , mustCall ( ( data ) => {
23
+ received += data . toString ( ) ;
24
+ } ) ) ;
25
+ c . on ( 'end' , mustCall ( ( ) => {
26
+ // Should not include anything else after asd.
27
+ assert . strictEqual ( received . indexOf ( 'asd\r\n' ) , received . length - 5 ) ;
28
+ c . end ( ) ;
29
+ } ) ) ;
30
+ c . on ( 'close' , mustCall ( ( ) => server . close ( ) ) ) ;
31
+ } ) ) ;
You can’t perform that action at this time.
0 commit comments