@ -1,30 +1,30 @@
'use strict' ;
require ( '../common' ) ;
var assert = require ( 'assert' ) ;
var http = require ( 'http' ) ;
var url = require ( 'url' ) ;
const assert = require ( 'assert' ) ;
const http = require ( 'http' ) ;
const url = require ( 'url' ) ;
var responses_sent = 0 ;
var responses_recvd = 0 ;
var body0 = '' ;
var body1 = '' ;
var server = http . Server ( function ( req , res ) {
if ( responses_sent == 0 ) {
assert . e qual( 'GET' , req . method ) ;
assert . e qual( '/hello' , url . parse ( req . url ) . pathname ) ;
const server = http . Server ( function ( req , res ) {
if ( responses_sent === 0 ) {
assert . strictE qual( 'GET' , req . method ) ;
assert . strictE qual( '/hello' , url . parse ( req . url ) . pathname ) ;
console . dir ( req . headers ) ;
assert . e qual( true , 'accept' in req . headers ) ;
assert . e qual( '*/*' , req . headers [ 'accept' ] ) ;
assert . strictE qual( true , 'accept' in req . headers ) ;
assert . strictE qual( '*/*' , req . headers [ 'accept' ] ) ;
assert . e qual( true , 'foo' in req . headers ) ;
assert . e qual( 'bar' , req . headers [ 'foo' ] ) ;
assert . strictE qual( true , 'foo' in req . headers ) ;
assert . strictE qual( 'bar' , req . headers [ 'foo' ] ) ;
}
if ( responses_sent == 1 ) {
assert . e qual( 'POST' , req . method ) ;
assert . e qual( '/world' , url . parse ( req . url ) . pathname ) ;
if ( responses_sent === 1 ) {
assert . strictE qual( 'POST' , req . method ) ;
assert . strictE qual( '/world' , url . parse ( req . url ) . pathname ) ;
this . close ( ) ;
}
@ -41,14 +41,14 @@ var server = http.Server(function(req, res) {
server . listen ( 0 ) ;
server . on ( 'listening' , function ( ) {
var agent = new http . Agent ( { port : this . address ( ) . port , maxSockets : 1 } ) ;
const agent = new http . Agent ( { port : this . address ( ) . port , maxSockets : 1 } ) ;
http . get ( {
port : this . address ( ) . port ,
path : '/hello' ,
headers : { 'Accept' : '*/*' , 'Foo' : 'bar' } ,
agent : agent
} , function ( res ) {
assert . e qual( 200 , res . statusCode ) ;
assert . strictE qual( 200 , res . statusCode ) ;
responses_recvd += 1 ;
res . setEncoding ( 'utf8' ) ;
res . on ( 'data' , function ( chunk ) { body0 += chunk ; } ) ;
@ -56,13 +56,13 @@ server.on('listening', function() {
} ) ;
setTimeout ( function ( ) {
var req = http . request ( {
const req = http . request ( {
port : server . address ( ) . port ,
method : 'POST' ,
path : '/world' ,
agent : agent
} , function ( res ) {
assert . e qual( 200 , res . statusCode ) ;
assert . strictE qual( 200 , res . statusCode ) ;
responses_recvd += 1 ;
res . setEncoding ( 'utf8' ) ;
res . on ( 'data' , function ( chunk ) { body1 += chunk ; } ) ;
@ -74,12 +74,11 @@ server.on('listening', function() {
process . on ( 'exit' , function ( ) {
console . error ( 'responses_recvd: ' + responses_recvd ) ;
assert . e qual( 2 , responses_recvd ) ;
assert . strictE qual( 2 , responses_recvd ) ;
console . error ( 'responses_sent: ' + responses_sent ) ;
assert . e qual( 2 , responses_sent ) ;
assert . strictE qual( 2 , responses_sent ) ;
assert . e qual( 'The path was /hello' , body0 ) ;
assert . e qual( 'The path was /world' , body1 ) ;
assert . strictE qual( 'The path was /hello' , body0 ) ;
assert . strictE qual( 'The path was /world' , body1 ) ;
} ) ;