Repository: jquery/jquery
File: test/middleware-mockserver.js (JavaScript)

Code before:
		}, next );
	},
	xmlOverJsonp: function( req, resp ) {
		var callback = req.query.callback;
		var body = fs.readFileSync( __dirname + "/data/with_fries.xml" ).toString();
		resp.writeHead( 200 );
		resp.end( callback + "(" + JSON.stringify( body ) + ")\n" );
	},
	error: function( req, resp ) {
		if ( req.query.json ) {
			resp.writeHead( 400, { "content-type": "application/json" } );
			resp.end( "{ \"code\": 40, \"message\": \"Bad Request\" }" );
		} else {
			resp.writeHead( 400 );
			resp.end( "plain text message" );
		}
	},
	headers: function( req, resp ) {
		resp.writeHead( 200, {
			"Sample-Header": "Hello World",
			"Empty-Header": "",
			"Sample-Header2": "Hello World 2",
			"List-Header": "Item 1",
			"list-header": "Item 2",
			"Constructor": "prototype collision (constructor)",
			"__Proto__": "prototype collision (__proto__)"
		} );
		req.query.keys.split( "|" ).forEach( function( key ) {
			if ( req.headers[ key.toLowerCase() ] ) {
				resp.write( key + ": " + req.headers[ key.toLowerCase() ] + "\n" );
			}
		} );
		resp.end();
	},
	echoData: function( req, resp, next ) {
		getBody( req ).then( function( body ) {
			resp.end( body );
		}, next );
	},
	echoQuery: function( req, resp ) {
		resp.end( req.parsed.search.slice( 1 ) );
	},
	echoMethod: function( req, resp ) {
		resp.end( req.method );
	},
	echoHtml: function( req, resp, next ) {
		resp.writeHead( 200, { "Content-Type": "text/html" } );
		resp.write( "<div id='method'>" + req.method + "</div>" );
		resp.write( "<div id='query'>" + req.parsed.search.slice( 1 ) + "</div>" );
		getBody( req ).then( function( body ) {
			resp.write( "<div id='data'>" + body + "</div>" );

Review comment (bug):
Let's omit the "Constructor" header and change the corresponding assertion to expect `null` (i.e., proving that we don't hit the built-in property when there's no response header to shadow it), and change the "\_\_Proto\_\_" header to lowercase (so that the assertion never fails by mistake if we key headers exactly as received).

Code after:
		}, next );
	},
	xmlOverJsonp: function( req, resp ) {
		var callback = req.query.callback;
		var body = fs.readFileSync( __dirname + "/data/with_fries.xml" ).toString();
		resp.writeHead( 200 );
		resp.end( callback + "(" + JSON.stringify( body ) + ")\n" );
	},
	error: function( req, resp ) {
		if ( req.query.json ) {
			resp.writeHead( 400, { "content-type": "application/json" } );
			resp.end( "{ \"code\": 40, \"message\": \"Bad Request\" }" );
		} else {
			resp.writeHead( 400 );
			resp.end( "plain text message" );
		}
	},
	headers: function( req, resp ) {
		resp.writeHead( 200, {
			"Sample-Header": "Hello World",
			"Empty-Header": "",
			"Sample-Header2": "Hello World 2",
			"List-Header": "Item 1",
			"list-header": "Item 2",
			"constructor": "prototype collision (constructor)"
		} );
		req.query.keys.split( "|" ).forEach( function( key ) {
			if ( req.headers[ key.toLowerCase() ] ) {
				resp.write( key + ": " + req.headers[ key.toLowerCase() ] + "\n" );
			}
		} );
		resp.end();
	},
	echoData: function( req, resp, next ) {
		getBody( req ).then( function( body ) {
			resp.end( body );
		}, next );
	},
	echoQuery: function( req, resp ) {
		resp.end( req.parsed.search.slice( 1 ) );
	},
	echoMethod: function( req, resp ) {
		resp.end( req.method );
	},
	echoHtml: function( req, resp, next ) {
		resp.writeHead( 200, { "Content-Type": "text/html" } );
		resp.write( "<div id='method'>" + req.method + "</div>" );
		resp.write( "<div id='query'>" + req.parsed.search.slice( 1 ) + "</div>" );
		getBody( req ).then( function( body ) {
			resp.write( "<div id='data'>" + body + "</div>" );
			resp.end( body );