2012-06-10 16:44:50 -07:00
|
|
|
function handleRequest(request, response) {
|
|
|
|
let invalidHeaders = ["Cookie"];
|
|
|
|
let headers = {};
|
|
|
|
|
|
|
|
if (request.queryString == "expectAuth=true") {
|
|
|
|
if (request.hasHeader("Authorization")) {
|
|
|
|
headers["authorization"] = request.getHeader("Authorization");
|
|
|
|
} else {
|
2012-10-24 07:05:13 -07:00
|
|
|
response.setStatusLine(null, 401, "Authentication required");
|
|
|
|
response.setHeader("WWW-Authenticate", "basic realm=\"testrealm\"", true);
|
2012-06-10 16:44:50 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
invalidHeaders.push("Authorization");
|
|
|
|
}
|
|
|
|
|
|
|
|
for each (let header in invalidHeaders) {
|
|
|
|
if (request.hasHeader(header)) {
|
|
|
|
response.setStatusLine(null, 500, "Server Error");
|
|
|
|
headers[header.toLowerCase()] = request.getHeader(header);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
response.write(JSON.stringify(headers));
|
|
|
|
}
|