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

Code before:
		resp.end();
	},
	cspClean: function( req, resp ) {
		cspLog = "";
		resp.writeHead( 200 );
		resp.end();
	},
	errorWithScript: function( req, resp ) {
		if ( req.query.withScriptContentType ) {
			resp.writeHead( 404, { "Content-Type": "application/javascript" } );
		} else {
			resp.writeHead( 404 );
		}
		if ( req.query.callback ) {
			resp.end( req.query.callback + "( {\"status\": 404, \"msg\": \"Not Found\"} )" );
		} else {
			resp.end( "QUnit.assert.ok( false, \"Mock return erroneously executed\" );" );
		}
	},
	cors: function( req, resp ) {
		if ( typeof req.headers[ "origin" ] != "undefined" ) {
			resp.setHeader( "Access-Control-Allow-Methods", "GET" );
			resp.setHeader( "Access-Control-Allow-Origin", req.headers[ "origin" ] );
			resp.end( "corsCallback(true)" );
		} else {
			resp.end( "corsCallback(false)" );
		}
	}
};
var handlers = {
	"test/data/mock.php": function( req, resp, next ) {
		if ( !mocks[ req.query.action ] ) {
			resp.writeHead( 400 );
			resp.end( "Invalid action query.\n" );
			console.log( "Invalid action query:", req.method, req.url );
			return;
		}
		mocks[ req.query.action ]( req, resp, next );
	},
	"test/data/support/csp.log": function( req, resp ) {
		resp.writeHead( 200 );
		resp.end( cspLog );
	},
	"test/data/404.txt": function( req, resp ) {
		resp.writeHead( 404 );
		resp.end( "" );
	}
};

/**
 * Connect-compatible middleware factory for mocking server responses.

Review comment (suggestion):
```suggestion
			resp.end( "corsCallback( false )" );
```

Code after:
		var body = fs.readFileSync( __dirname + "/data/csp.include.html" ).toString();
		resp.end( body );
	},
	cspNonce: function( req, resp ) {
		var testParam = req.query.test ? "-" + req.query.test : "";
		resp.writeHead( 200, {
			"Content-Type": "text/html",
			"Content-Security-Policy": "script-src 'nonce-jquery+hardcoded+nonce'; report-uri /base/test/data/mock.php?action=cspLog"
		} );
		var body = fs.readFileSync(
			__dirname + "/data/csp-nonce" + testParam + ".html" ).toString();
		resp.end( body );
	},
	cspAjaxScript: function( req, resp ) {
		resp.writeHead( 200, {
			"Content-Type": "text/html",
			"Content-Security-Policy": "script-src 'self'; report-uri /base/test/data/mock.php?action=cspLog"
		} );
		var body = fs.readFileSync(
			__dirname + "/data/csp-ajax-script.html" ).toString();
		resp.end( body );
	},
	cspLog: function( req, resp ) {
		cspLog = "error";
		resp.writeHead( 200 );
		resp.end();
	},
	cspClean: function( req, resp ) {
		cspLog = "";
		resp.writeHead( 200 );
		resp.end();
	},
	errorWithScript: function( req, resp ) {
		if ( req.query.withScriptContentType ) {
			resp.writeHead( 404, { "Content-Type": "application/javascript" } );
		} else {
			resp.writeHead( 404 );
		}
		if ( req.query.callback ) {
			resp.end( req.query.callback + "( {\"status\": 404, \"msg\": \"Not Found\"} )" );
		} else {
			resp.end( "QUnit.assert.ok( false, \"Mock return erroneously executed\" );" );
		}
	}
};
var handlers = {
	"test/data/mock.php": function( req, resp, next ) {
		if ( !mocks[ req.query.action ] ) {
			resp.writeHead( 400 );
			resp.end( "Invalid action query.\n" );
			console.log( "Invalid action query:", req.method, req.url );