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

responseHeaders not available until readyState 4 (expected 2) #2460

Closed
Rob--W opened this issue Dec 15, 2016 · 3 comments
Closed

responseHeaders not available until readyState 4 (expected 2) #2460

Rob--W opened this issue Dec 15, 2016 · 3 comments
Milestone

Comments

@Rob--W
Copy link

Rob--W commented Dec 15, 2016

In XMLHttpRequest, there are multiple readyStates of interest: 2 (response headers received)and 4 (load finished).

I created a script that checks responseHeaders at readyState 2, and if it indicates support for range requests, I abort the request and restart the request with a much smaller range.
In theory, this works. However, it does not work in GreaseMonkey because it only sets the headers when the request has fully finished:

if (4 != req.readyState) break;
responseState.responseHeaders = req.getAllResponseHeaders();

git blame shows that this logic was already in place in the initial commit of the repo, so I did not discover why the implementation is like this.

This, and the fact that HTTP cookies are not included in the request is the reason why I switched to a full WebExtension for the script. It would still be good to fix the issue in GM though.

@janekptacijarabaci
Copy link
Contributor

janekptacijarabaci commented Dec 15, 2016

git blame shows that this logic was already in place in the initial commit of the repo, so I did not discover why the implementation is like this.

AFAIK not:
https://addons.mozilla.org/cs/firefox/files/browse/3733/file/chrome/greasemonkey/content/xmlhttprequester.js#L123

But if there isn't a serious reason for not:
#2461

the fact that HTTP cookies are not included in the request

See also #2236

But AFAIK, you can use:
"headers": {
"cookie": document.cookie
},

See also #1802

@Rob--W
Copy link
Author

Rob--W commented Dec 15, 2016

"AFAIK not" = "there is no reason for the limitation"?

That cookie suggestion does not work for http-only cookies, and neither for redirects.

@janekptacijarabaci
Copy link
Contributor

I edited it, I'm sorry.

There is no reason for the limitation?

I think it's for no reason. AFAIK.

@arantius arantius added this to the 3.10 milestone Dec 15, 2016
@arantius arantius modified the milestones: 3.10, 3.11 Feb 22, 2017
@arantius arantius modified the milestones: 3.11, 3.12 Mar 13, 2017
@arantius arantius modified the milestones: 3.12, Bankruptcy Jul 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants