OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <script src="/js-test-resources/js-test.js"></script> |
| 3 <script> |
| 4 window.jsTestIsAsync = true; |
| 5 description('Multiple calls to XMLHttpRequest.setRequestHeader() with ' + |
| 6 'the same header name and header values with leading/trailing ' + |
| 7 'whitespaces should show a deprecation message.'); |
| 8 |
| 9 // According to the XHR spec [1], normalization (removing leading/trailing |
| 10 // whitespaces) must be done on the value argument on setRequestHeader() call. |
| 11 // Currently Blink's XHR implementation doesn't do the normalization, but other |
| 12 // parts of Chromium do the normalization after setRequestHeader() and before |
| 13 // headers are sent to network. |
| 14 // A deprecation warning should be shown if the headers sent to the network is |
| 15 // affected by introducing header value normalization in Blink's XHR. |
| 16 // [1] https://xhr.spec.whatwg.org/#dom-xmlhttprequest-setrequestheader |
| 17 // https://crbug.com/455099 |
| 18 |
| 19 var xhr = new XMLHttpRequest; |
| 20 xhr.open("GET", "../resources/print-headers.cgi"); |
| 21 |
| 22 // The leading/trailing whitespaces are not removed by Chromium after |
| 23 // setRequestHeader() if there are multiple setRequestHeader() calls with |
| 24 // the same header name because it is applied the header value concatenated by |
| 25 // ', ' in setRequestHeader(). |
| 26 // In the following case, |
| 27 // a1. Blink's XHR creates the header value 'a , b', |
| 28 // a2. Chromium normalizes 'a , b' but does nothing, and |
| 29 // a3. 'a , b' is sent to the network. |
| 30 // If we introduce header value normalization in Blink's XHR, then: |
| 31 // b1. Blink's XHR creates the header value 'a, b' because it normalizes |
| 32 // 'a ' and 'b' into 'a' and 'b', respectively, before concatenating by |
| 33 // ', '. |
| 34 // b2. Chromium normalizes 'a, b' but does nothing, and |
| 35 // b3. 'a, b' is sent to the network. |
| 36 // a3 and b3 are different, so a deprecation warning should be shown. |
| 37 xhr.setRequestHeader('test1', 'a '); |
| 38 xhr.setRequestHeader('test1', 'b'); |
| 39 |
| 40 xhr.onload = function() { |
| 41 // This expectation must be updated once we update header value checks. |
| 42 shouldNotBe('xhr.responseText.match(/HTTP_TEST1: a , b\\r?\\n/)', |
| 43 'null'); |
| 44 finishJSTest(); |
| 45 }; |
| 46 xhr.onerror = function() { |
| 47 testFailed(); |
| 48 finishJSTest(); |
| 49 }; |
| 50 xhr.send(); |
| 51 </script> |
OLD | NEW |