Truly independent web browser
<!doctype html>
<script src="../include.js"></script>
<script>
promiseTest(async () => {
const server = httpTestServer();
const path = "/url-credentials-authorization-header";
const url = new URL(
await server.createEcho("GET", path, {
status: 401,
headers: { "WWW-Authenticate": 'Basic realm="test"' },
})
);
// The 401 challenge makes fetch retry the request with an `Authorization` header built from the credentials.
const xhr = new XMLHttpRequest();
xhr.open("GET", `${url.protocol}//user:pass@${url.host}${url.pathname}`);
await new Promise(resolve => {
xhr.addEventListener("loadend", resolve);
xhr.send();
});
const response = await fetch(server.recordedRequestHeadersURL(url));
println(`Authorization: ${(await response.json())["Authorization"]?.[0]}`);
});
</script>