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

feature request: redirectionLimit #1690

Closed
specu opened this Issue Jan 17, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@specu
Copy link

specu commented Jan 17, 2013

Forgive me if this is the wrong place.

I would like to propose modification for GM_xmlhttpRequest to allow imposing limitations on redirections. Currently it is perceived that the underlying function redirects transparently due to the standard but there's a workaround to prevent redirection. This allows bigger flexibilty of GM_xmlhttpRequest scripting.
http://stackoverflow.com/questions/7524039/problems-with-xmlhttprequest-status-302/7525294#7525294
The linked example allows to set redirectionLimit to 0 allowing the script to see the path of redirection. Currently it is transparent to the script.

So in essence I'm proposing adding argument redirectionLimit to GM_xmlhttpRequest so for example bare minimum example from wiki would look like:

GM_xmlhttpRequest({
  method: "GET",
  url: "http://www.example.com/",
  redirectionLimit: 0,
  onload: function(response) {
    alert(response.responseText);
  }
});

So that if the response is for example 302 redirect script would be able to read the 302 status and Location argument etc. Obviously that's just one application.

@arantius

This comment has been minimized.

Copy link
Collaborator

arantius commented Feb 1, 2013

Note that if the request is stopped due to reaching the redirection limit, onload is never called, so you must do i.e.

GM_xmlhttpRequest({
  method: "GET",
  url: "http://goo.gl/vDSk9",
  redirectionLimit: 0,
  onreadystatechange: function(response) {
    if (response.readyState != 4) return;
    console.log(response.responseHeaders.match(/^Location.*/m));
  }
});

@arantius arantius closed this in 2024ce1 Feb 1, 2013

@specu

This comment has been minimized.

Copy link

specu commented Feb 2, 2013

Awesome, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment