File tree 1 file changed +46
-0
lines changed
1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const common = require ( '../common' ) ;
4
+
5
+ const assert = require ( 'assert' ) ;
6
+ const http = require ( 'http' ) ;
7
+ const net = require ( 'net' ) ;
8
+
9
+ const msg = [
10
+ 'POST / HTTP/1.1' ,
11
+ 'Host: 127.0.0.1' ,
12
+ 'Transfer-Encoding: chunked' ,
13
+ 'Transfer-Encoding: chunked-false' ,
14
+ 'Connection: upgrade' ,
15
+ '' ,
16
+ '1' ,
17
+ 'A' ,
18
+ '0' ,
19
+ '' ,
20
+ 'GET /flag HTTP/1.1' ,
21
+ 'Host: 127.0.0.1' ,
22
+ '' ,
23
+ '' ,
24
+ ] . join ( '\r\n' ) ;
25
+
26
+ // Verify that the server is called only once even with a smuggled request.
27
+
28
+ const server = http . createServer ( common . mustCall ( ( req , res ) => {
29
+ res . end ( ) ;
30
+ } , 1 ) ) ;
31
+
32
+ function send ( next ) {
33
+ const client = net . connect ( server . address ( ) . port , 'localhost' ) ;
34
+ client . setEncoding ( 'utf8' ) ;
35
+ client . on ( 'error' , common . mustNotCall ( ) ) ;
36
+ client . on ( 'end' , next ) ;
37
+ client . write ( msg ) ;
38
+ client . resume ( ) ;
39
+ }
40
+
41
+ server . listen ( 0 , common . mustCall ( ( err ) => {
42
+ assert . ifError ( err ) ;
43
+ send ( common . mustCall ( ( ) => {
44
+ server . close ( ) ;
45
+ } ) ) ;
46
+ } ) ) ;
You can’t perform that action at this time.
0 commit comments