Skip to content

Instantly share code, notes, and snippets.

@josephbolus
Last active January 19, 2023 21:05
Show Gist options
  • Save josephbolus/6e97e579c6026de85c8f7f9abe083133 to your computer and use it in GitHub Desktop.
Save josephbolus/6e97e579c6026de85c8f7f9abe083133 to your computer and use it in GitHub Desktop.
<script>
function parseHttpHeaders(httpHeaders) {
return httpHeaders.split("\n")
.map(x=>x.split(/: */,2))
.filter(x=>x[0])
.reduce((ac, x)=>{ac[x[0]] = x[1];return ac;}, {});
}
var req = new XMLHttpRequest();
req.open('GET', document.location, false);
req.send(null);
var headers = parseHttpHeaders(req.getAllResponseHeaders());
// Now we can do: headers["content-type"]
console.log('HTTP Headers Debug:');
console.log('x-forwarded-user: ' + headers["x-forwarded-user"]);
console.log('x-forwarded-email: ' + headers["x-forwarded-email"]);
console.log('x-auth-request-email: ' + headers["x-auth-request-email"]);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment