preflight-failure.htm (1882B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>CORS - Preflight responds with non-2XX status code</title> 4 <meta name=author title="Fernando Jiménez Moreno" href="mailto:ferjmoreno@gmail.com"> 5 6 <script src=/resources/testharness.js></script> 7 <script src=/resources/testharnessreport.js></script> 8 <script src=/common/get-host-info.sub.js></script> 9 10 <h1>Preflight responds with non-2XX status code</h1> 11 12 <div id=log></div> 13 <script> 14 15 // Request count for cache busting and easy identifying of request in traffic 16 // analyzer. 17 var req_c = 0; 18 19 var CROSSDOMAIN_URL = get_host_info().HTTP_REMOTE_ORIGIN + '/cors/resources/cors-makeheader.py?'; 20 21 /* 22 * Redirection with preflights. 23 */ 24 function preflight_failure(code) { 25 var isCodeOK = code >= 200 && code <= 299, 26 descOK = isCodeOK ? 'succeed' : 'throw error', 27 desc = 'Should ' + descOK + ' if preflight has status ' + code; 28 async_test(desc).step(function() { 29 var client = new XMLHttpRequest(); 30 var redirect = 31 encodeURIComponent(CROSSDOMAIN_URL + 'headers=x-test&' + req_c++); 32 33 client.open('GET', 34 CROSSDOMAIN_URL + 'headers=x-test&location=' + redirect 35 + '&code=' + code + '&preflight=' + code 36 + '&' + req_c++, 37 true /* async */); 38 client.setRequestHeader('x-test', 'test'); 39 client.onerror = this.step_func(function() { 40 assert_false(isCodeOK); 41 this.done(); 42 }); 43 client.onreadystatechange = this.step_func(function() { 44 if (!isCodeOK) 45 assert_equals(client.status, 0); 46 }); 47 client.onload = this.step_func(function() { 48 assert_true(isCodeOK); 49 this.done(); 50 }); 51 client.send(null); 52 }); 53 } 54 [200, 299, 55 300, 301, 302, 303, 304, 305, 306, 307, 308, 56 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 57 500, 501, 502, 503, 504, 505, 58 680, 59 790 60 ].forEach(preflight_failure); 61 62 </script>