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] Making HTTP requests to redirects. #929

Closed
3rd-Eden opened this issue Apr 20, 2015 · 13 comments
Closed

[XMLHttpRequest] Making HTTP requests to redirects. #929

3rd-Eden opened this issue Apr 20, 2015 · 13 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@3rd-Eden
Copy link

I'm in the process of implementing an login against an oauth based third-party server. As part of the login procedure I need to make an HTTP requests to an endpoint that returns a 302 status code with new Location header and vital session cookies that I need to intercept. Unfortunately the XMLHTTPRequest and the fetch API will automatically follow these redirect so there is no way of accessing or intercepting the required HTTP headers that contain authorization information.

So what I would like to suggest is:

  • Add a non standard nofollow = true property to these API's so we as users can handle the redirect logic our selfs.
  • Provide a much lower level HTTP interface much like Node's http module so we can build our own requests modules and use the modules such as request from npm.
  • Provide a tcp interface so we can add HTTP parsing and WebSocket frame parsing on top of it.
@nicklockwood
Copy link
Contributor

Of these, I find option 2 (polyfill the node http module) most appealing. Specifically the http.request() and http.get() methods.

Do you feel like trying to build it? :-)

http://nodejs.org/docs/v0.4.11/api/http.html#http.request

@vjeux
Copy link
Contributor

vjeux commented Apr 27, 2015

You are right, XHR won't let you handle redirects yourself by design :( http://stackoverflow.com/questions/228225/prevent-redirection-of-xmlhttprequest

@3rd-Eden
Copy link
Author

@nicklockwood A polyfill had my preference as well but I can see potential problems with it now that the package/module system follows the browser field in the package.json as it would mean that modules such as superagent would still use their browser equivalent and fallback to XHR instead of the http module.

I've been looking on implementing this all in Objective-C and possibility using the AFNetworking library to hide Objective-C's bad parts but so far, my knowledge has been lacking and I haven't made any fruitful process. :p

@nicklockwood
Copy link
Contributor

@vjeux sadly my knowledge of node conventions is lacking. If I were to provide a polyfill for Node's http module, would there be a practical way to switch React Native into "server mode" so that modules would use that instead of our XHR polyfill, or am I barking up the wrong tree?

@vjeux
Copy link
Contributor

vjeux commented Apr 27, 2015

@3rd-Eden do you know if you are able to login to your 3rd party via web? If yes (which seems likely) then there must be another way to do it right? Before going down the rabbit hole of making nofollow working, I wonder if there's an easier way

@3rd-Eden
Copy link
Author

@vjeux I absolutely wished that there is a way around this insanity. The hacks that I have to use in order to consume this API are almost impossible to describe with words but here's what I'm up to. I'm building an application that interacts with the platform API of Bungie.net. You can login to bungie with either your XBox or PlayStation accounts. When you login using oAuth you get redirected and on the redirect landing page, bungie is setting cookies that are required to access parts of their "private" API. Without this information you cannot modify your account etc. So I need access to all cookies, not those can be retrieved using document.cookie in browsers but also the HTTP only cookies as these are the cookies that control if have access or not. So the main problem here is that the API does not provide a way to simply login and nor do they have plans of implementing this. There are basically 2 options that I have in order to get the information required:

@vjeux
Copy link
Contributor

vjeux commented Apr 28, 2015

Yeah this seems crazy indeed. My recommendation to you would be to write all the code that does the request, extracts the cookie, ... in obj-c via iOS networking stack and then expose a single method for js: login(cb).

http://facebook.github.io/react-native/docs/nativemodulesios.html#content

This is going to solve your particular issue. If this becomes a common pain point for people, then we can figure out a more elegant solution

@brentvatne brentvatne changed the title Making HTTP requests to redirects. [XMLHttpRequest] Making HTTP requests to redirects. May 30, 2015
@ghost
Copy link

ghost commented Aug 4, 2015

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

@mkonicek
Copy link
Contributor

Hi there! This issue is being closed because it has been inactive for a while.

But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/xmlhttprequest-making-http-requests-to-redirects

ProductPains helps the community prioritize the most important issues thanks to its voting feature.
It is easy to use - just login with GitHub.

Also, if this issue is a bug, please consider sending a PR with a fix. We rely on the community to provide
bugfixes as the core team is focused on performance.

@GetSource1234
Copy link

I spotted the same issue (RN 0.48.1). Redirect occurs automatically witin fetch request. redirect: 'manual', doesn't help.

@3rd-Eden
Copy link
Author

Yes the issue is not fixed, it just get automatically closed for some odd reason even though it's valid report.

@twelve17
Copy link

In case this might help, per this SO response, you can use HEAD to get the location. Seems like the redirect won't be followed on HEAD (or alternatively OPTIONS).

@Meshz
Copy link

Meshz commented Mar 19, 2018

I experience exactly the same problem while using the fetch API on Android. Anybody has a hint on how to fix this in source code? Or if redirect: 'manual' will ever be implemented?

@facebook facebook locked as resolved and limited conversation to collaborators Jul 22, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

8 participants