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

Get response url from XMLHttpRequest #4981

Closed
wants to merge 1 commit into from

Conversation

realaboo
Copy link
Contributor

An HTTP request may be redirected to another URL, sometimes we need to know the URL where the response comes from.

If the server is in control, we can add an HTTP header X-Request-URL for the redirect URL. However there will be cases that 3rd party services are used.

This PR retrieves the response URL from native networking module and passes to it XMLHttpRequest. The fetch API built on XMLHttpRequest also benefits from this feature.

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @nicklockwood, @philikon and @lexs to be potential reviewers.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Dec 26, 2015
if (requestId === this._requestId) {
this.status = status;
this.setResponseHeaders(responseHeaders);
this.setReadyState(this.HEADERS_RECEIVED);
if (responseURL) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property responseURL Property not found in XMLHttpRequestBase

@facebook-github-bot
Copy link
Contributor

@realaboo updated the pull request.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@realaboo updated the pull request.

@satya164
Copy link
Contributor

cc @mkonicek

StyleSheet,
Text,
TextInput,
TouchableHighlight,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no-unused-vars: "TouchableHighlight" is defined but never used

@facebook-github-bot
Copy link
Contributor

@realaboo updated the pull request.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@realaboo updated the pull request.

@mkonicek
Copy link
Contributor

mkonicek commented Jan 6, 2016

@lexs Does this look OK to you?

@@ -352,7 +352,7 @@ var self = {};
var xhr = new XMLHttpRequest()

function responseURL() {
if ('responseURL' in xhr) {
if ('responseURL' in xhr && xhr.responseURL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing this in fetch.js (which is upstream) could we delete responseURL if it is null? I'm not 100% sure what this means in this context as I'm guessing it will never be null in our case?

The spec says this:

The responseURL attribute must return the empty string if response's url is null and its serialization with the exclude fragment flag set otherwise.

I'd be ok with just deleting the property if it's null. Seems reasonable?

@facebook-github-bot
Copy link
Contributor

@realaboo updated the pull request.

@realaboo
Copy link
Contributor Author

realaboo commented Jan 7, 2016

@lexs I've updated the commit. Sorry but I'm new to ES6. I'm not sure if it's OK to declare a class member first and then delete it later somewhere else. Thanks for the review.

@lexs
Copy link
Contributor

lexs commented Jan 7, 2016

@realaboo That's an interesting question, it's definitely ok JS-wise but Flow might be less happy. Nothing blocking this tho.

@lexs
Copy link
Contributor

lexs commented Jan 7, 2016

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1532998640345120/int_phab to review.

@ghost ghost closed this in b659d7f Jan 7, 2016
christopherdro pushed a commit to wildlifela/react-native that referenced this pull request Jan 20, 2016
Summary:
An HTTP request may be redirected to another URL, sometimes we need to know the URL where the  response comes from.

If the server is in control, we can add an HTTP header X-Request-URL for the redirect URL. However there will be cases that 3rd party services are used.

This PR retrieves the response URL from native networking module and passes to it XMLHttpRequest. The fetch API built on XMLHttpRequest also benefits from this feature.
Closes facebook#4981

Reviewed By: svcscm

Differential Revision: D2811392

Pulled By: lexs

fb-gh-sync-id: 3ec356fb92f8011b6a243d6879172877a3dc498a
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants