Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XMLHttpRequest.getAllResponseHeaders should return lowercase header fields in sorted order #32353

Closed
ascherkus opened this issue Oct 7, 2021 · 2 comments
Labels
Needs: Triage 🔍 🌐Networking Related to a networking API. Platform: Linux Building on Linux. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@ascherkus
Copy link
Contributor

Description

The getAllResponseHeaders() specification indicates that "Let initialHeaders be the result of running sort and combine with this’s response’s header list", where a sort and combine is defined in the Fetch specification as "the result of convert header names to a sorted-lowercase set with all the names of the headers in list."

Basically we should expect to see "content-type" not "Content-Type" similar to what you'd see when running on a web browser.

React Native version:

System:
OS: Linux 5.4 Ubuntu 20.04.3 LTS (Focal Fossa)
CPU: (8) x64 Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz
Memory: 3.14 GB / 31.31 GB
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 16.10.0 - /tmp/yarn--1633648470824-0.633831050292539/node
Yarn: 1.19.1 - /tmp/yarn--1633648470824-0.633831050292539/yarn
npm: 7.24.0 - /usr/bin/npm
Watchman: Not Found
SDKs:
Android SDK:
API Levels: 29, 30, 31
Build Tools: 29.0.3, 30.0.2, 31.0.0
System Images: android-29 | Intel x86 Atom_64, android-29 | Google Play Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: Not Found
Languages:
Java: 11.0.11 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.66.0 => 0.66.0
npmGlobalPackages:
react-native: Not Found
Done in 2.82s.

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Start up a HTTP/1 webserver that returns uppercased headers (e.g., Content-Type versus content-type -- HTTP/2 requires headers to be lowercased)
  2. Request something via XMLHttpRequest and call getAllResponseHeaders():
let xhr = new XMLHttpRequest();
xhr.addEventListener('readystatechange', function (e) {
  if (xhr.readyState == 4) {
    console.log(xhr.getAllResponseHeaders());
  }
});

// Replace with your test server -- I couldn't easily find a public facing one
// since most appear to run through proxies that don't exhibit the desired behaviour.
xhr.open('GET', 'https://uppercase-headers-http1.com/');
xhr.send();

Expected Results

A sorted list of the headers with the field names lowercased. For example:

[
"content-type: application/json",
"transfer-encoding: chunked"
]

Instead the headers fields are retured verbatim:

[
"Content-Type: application/json",
"Transfer-Encoding: chunked"
]

I think the fix in https://github.com/facebook/react-native/blob/main/Libraries/Network/XMLHttpRequest.js#L421 isn't too bad -- perhaps we should be using this._lowerCaseResponseHeaders and sort the result instead of this.responseHeaders?

@react-native-bot react-native-bot added 🌐Networking Related to a networking API. Platform: Linux Building on Linux. labels Oct 7, 2021
ascherkus added a commit to ascherkus/react-native that referenced this issue Oct 8, 2021
…eHeaders() (facebook#32353)

As per the XMLHttpRequest specification [1], getAllResponseHeaders() should
return a string of headers with lowercased names and sorted by their uppercase
representation, with each header ending with '\r\n'.

[1] https://xhr.spec.whatwg.org/#the-getallresponseheaders()-method
facebook-github-bot pushed a commit that referenced this issue Oct 26, 2021
…#32363)

Summary:
As per the XMLHttpRequest specification [1], getAllResponseHeaders() should return a string of headers with lowercased names and sorted by their uppercase representation, with each header ending with '\r\n'.

[1] https://xhr.spec.whatwg.org/#the-getallresponseheaders()-method

## Changelog

[General] [Changed] XMLHttpRequest.getAllResponseHeaders() now returns headers with names lowercased and sorted in ascending order, as per specification

Pull Request resolved: #32363

Test Plan:
Test derived from Web Platform Test repository:
https://github.com/web-platform-tests/wpt/tree/master/xhr

Reviewed By: yungsters

Differential Revision: D31626217

Pulled By: sota000

fbshipit-source-id: 299d005facbe1c15b8cda5eed6750db75addca80
@stale
Copy link

stale bot commented Jan 9, 2022

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jan 9, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

@facebook facebook locked as resolved and limited conversation to collaborators Jan 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs: Triage 🔍 🌐Networking Related to a networking API. Platform: Linux Building on Linux. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

2 participants