@@ -6,49 +6,90 @@ if (!common.hasCrypto)
66const assert = require ( 'assert' ) ;
77const http2 = require ( 'http2' ) ;
88
9- const testResBody = 'other stuff!\n' ;
9+ {
10+ const testResBody = 'other stuff!\n' ;
1011
11- // Checks the full 100-continue flow from client sending 'expect: 100-continue'
12- // through server receiving it, sending back :status 100, writing the rest of
13- // the request to finally the client receiving to.
12+ // Checks the full 100-continue flow from client sending 'expect: 100-continue'
13+ // through server receiving it, sending back :status 100, writing the rest of
14+ // the request to finally the client receiving to.
1415
15- const server = http2 . createServer ( ) ;
16+ const server = http2 . createServer ( ) ;
1617
17- let sentResponse = false ;
18+ let sentResponse = false ;
1819
19- server . on ( 'request' , common . mustCall ( ( req , res ) => {
20- res . end ( testResBody ) ;
21- sentResponse = true ;
22- } ) ) ;
20+ server . on ( 'request' , common . mustCall ( ( req , res ) => {
21+ res . end ( testResBody ) ;
22+ sentResponse = true ;
23+ } ) ) ;
24+
25+ server . listen ( 0 ) ;
26+
27+ server . on ( 'listening' , common . mustCall ( ( ) => {
28+ let body = '' ;
2329
24- server . listen ( 0 ) ;
30+ const client = http2 . connect ( `http://localhost:${ server . address ( ) . port } ` ) ;
31+ const req = client . request ( {
32+ ':method' : 'POST' ,
33+ 'expect' : '100-continue'
34+ } ) ;
2535
26- server . on ( 'listening' , common . mustCall ( ( ) => {
27- let body = '' ;
36+ let gotContinue = false ;
37+ req . on ( 'continue' , common . mustCall ( ( ) => {
38+ gotContinue = true ;
39+ } ) ) ;
2840
29- const client = http2 . connect ( `http://localhost:${ server . address ( ) . port } ` ) ;
30- const req = client . request ( {
31- ':method' : 'POST' ,
32- 'expect' : '100-continue'
33- } ) ;
41+ req . on ( 'response' , common . mustCall ( ( headers ) => {
42+ assert . strictEqual ( gotContinue , true ) ;
43+ assert . strictEqual ( sentResponse , true ) ;
44+ assert . strictEqual ( headers [ ':status' ] , 200 ) ;
45+ req . end ( ) ;
46+ } ) ) ;
3447
35- let gotContinue = false ;
36- req . on ( 'continue' , common . mustCall ( ( ) => {
37- gotContinue = true ;
48+ req . setEncoding ( 'utf8' ) ;
49+ req . on ( 'data' , common . mustCall ( ( chunk ) => { body += chunk ; } ) ) ;
50+ req . on ( 'end' , common . mustCall ( ( ) => {
51+ assert . strictEqual ( body , testResBody ) ;
52+ client . close ( ) ;
53+ server . close ( ) ;
54+ } ) ) ;
3855 } ) ) ;
56+ }
57+
58+ {
59+ // Checks the full 100-continue flow from client sending 'expect: 100-continue'
60+ // through server receiving it and ending the request.
61+
62+ const server = http2 . createServer ( ) ;
3963
40- req . on ( 'response' , common . mustCall ( ( headers ) => {
41- assert . strictEqual ( gotContinue , true ) ;
42- assert . strictEqual ( sentResponse , true ) ;
43- assert . strictEqual ( headers [ ':status' ] , 200 ) ;
44- req . end ( ) ;
64+ server . on ( 'request' , common . mustCall ( ( req , res ) => {
65+ res . end ( ) ;
4566 } ) ) ;
4667
47- req . setEncoding ( 'utf8' ) ;
48- req . on ( 'data' , common . mustCall ( ( chunk ) => { body += chunk ; } ) ) ;
49- req . on ( 'end' , common . mustCall ( ( ) => {
50- assert . strictEqual ( body , testResBody ) ;
51- client . close ( ) ;
52- server . close ( ) ;
68+ server . listen ( 0 ) ;
69+
70+ server . on ( 'listening' , common . mustCall ( ( ) => {
71+ const client = http2 . connect ( `http://localhost:${ server . address ( ) . port } ` ) ;
72+ const req = client . request ( {
73+ ':path' : '/' ,
74+ 'expect' : '100-continue'
75+ } ) ;
76+
77+ let gotContinue = false ;
78+ req . on ( 'continue' , common . mustCall ( ( ) => {
79+ gotContinue = true ;
80+ } ) ) ;
81+
82+ let gotResponse = false ;
83+ req . on ( 'response' , common . mustCall ( ( ) => {
84+ gotResponse = true ;
85+ } ) ) ;
86+
87+ req . setEncoding ( 'utf8' ) ;
88+ req . on ( 'end' , common . mustCall ( ( ) => {
89+ assert . strictEqual ( gotContinue , true ) ;
90+ assert . strictEqual ( gotResponse , true ) ;
91+ client . close ( ) ;
92+ server . close ( ) ;
93+ } ) ) ;
5394 } ) ) ;
54- } ) ) ;
95+ }
0 commit comments