send-authentication-basic-setrequestheader.htm (1635B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>XMLHttpRequest: send() - "Basic" authenticated request using setRequestHeader()</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/common/utils.js"></script> 8 <!-- These spec references do not make much sense simply because the spec doesn't say very much about this.. --> 9 <link rel="help" href="https://xhr.spec.whatwg.org/#the-setrequestheader()-method" data-tested-assertations="following::ol[1]/li[6]" /> 10 <link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="following::code[contains(@title,'http-authorization')]/.." /> 11 </head> 12 <body> 13 <div id="log"></div> 14 <script> 15 var test = async_test() 16 test.step(function() { 17 var client = new XMLHttpRequest(), 18 urlstart = location.host + location.pathname.replace(/\/[^\/]*$/, '/'), 19 user = token() 20 client.open("GET", location.protocol+'//'+urlstart + "resources/auth2/auth.py", false) 21 client.setRequestHeader("x-user", user) 22 client.setRequestHeader('Authorization', 'Basic ' + btoa(user + ":pass")) 23 client.onreadystatechange = function () { 24 if (client.readyState < 4) {return} 25 test.step( function () { 26 assert_equals(client.responseText, user + '\npass') 27 assert_equals(client.status, 200) 28 assert_equals(client.getResponseHeader('x-challenge'), 'DID-NOT') 29 test.done() 30 } ) 31 } 32 client.send(null) 33 }) 34 </script> 35 </body> 36 </html>