File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const common = require ( '../common' ) ;
4+ const http = require ( 'http' ) ;
5+ const net = require ( 'net' ) ;
6+ const assert = require ( 'assert' ) ;
7+
8+ // Verify that a request with a space before the content length will result
9+ // in a 400 Bad Request.
10+
11+ const server = http . createServer ( common . mustNotCall ( ) ) ;
12+
13+ server . listen ( 0 , common . mustCall ( start ) ) ;
14+
15+ function start ( ) {
16+ const sock = net . connect ( server . address ( ) . port ) ;
17+
18+ sock . write ( 'GET / HTTP/1.1\r\nHost: localhost:5000\r\n' +
19+ 'Content-Length : 5\r\n\r\nhello' ) ;
20+
21+ let body = '' ;
22+ sock . setEncoding ( 'utf8' ) ;
23+ sock . on ( 'data' , ( chunk ) => {
24+ body += chunk ;
25+ } ) ;
26+ sock . on ( 'end' , common . mustCall ( function ( ) {
27+ assert . strictEqual ( body , 'HTTP/1.1 400 Bad Request\r\n' +
28+ 'Connection: close\r\n\r\n' ) ;
29+ server . close ( ) ;
30+ } ) ) ;
31+ }
You can’t perform that action at this time.
0 commit comments