', `
`);
}
response.end(content, 'utf-8');
debug('[%s] Serving %s with content-type %s', Date.now(), filePath, contentType);
});
}
function parseBasicAuth(auth) {
// auth is like `Basic Y2hhcmxlczoxMjM0NQ==`
var tmp = auth.split(' ');
var buf = Buffer.from(tmp[1], 'base64');
var plain = buf.toString();
var creds = plain.split(':');
return {
username: creds[0],
password: creds[1]
}
}
function sendBasicAuthResponse(response) {
response.writeHead(401, {
'Content-Type': 'text/html',
'WWW-Authenticate': 'Basic realm="Authentication service"'
});
return response.end('401 Unauthorized');
}