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

Incorrect Request implementation #177

Closed
cesarandreu opened this issue Jul 16, 2015 · 4 comments · Fixed by #179
Closed

Incorrect Request implementation #177

cesarandreu opened this issue Jul 16, 2015 · 4 comments · Fixed by #179

Comments

@cesarandreu
Copy link

Operating system: OS X Yosemite Version 10.10.4
Browser: Safari Version 8.0.7 (10600.7.12)

I've been developing with the following browsers:

  • Firefox Developer Edition 41.0a2 (2015-07-14)
  • Google Chrome Canary Version 46.0.2456.0 canary (64-bit)

Both Firefox and Chrome implement the expected behavior.

Code sample:

var request = new Request('/foo')
console.log(request.url)
// Chrome: "https://babeljs.io/foo"
// Safari: "/foo"

var request2 = new Request(request)
console.log(request2.url)
// Chrome: "https://babeljs.io/foo"
// Safari: {"url":"/foo","credentials":"omit","headers":{"map":{}},"method":"GET","mode":null,"referrer":null,"_bodyText":""}

The implementation in this repository is always taking the first parameter and setting it as the URL, but this is inconsistent with the standard, which allows you to pass a Request instance as the first parameter.

In the short-term, please consider adding a note to the README to inform users of this inconsistency. Tracking down this issue in Safari proved to be quite tricky for my project.

@mislav
Copy link
Contributor

mislav commented Jul 17, 2015

Are you using fetch v0.8 or greater? ab1ac93

@cesarandreu
Copy link
Author

Yeah, I'm on v0.9.

The problem is caused because when you create a new Request from an existing request, it's always setting the first param as the url. The spec for the Request class' first param is RequestInfo, and the typedef says it can be a USVString or a Request.

var r = new Request('/foo')
console.log(r.url)

var f = new Request(r)
console.log(f.url)

fetch(f)

If you try out the code above, in Safari it'll fetch /[object%20Object] instead of /foo.

@mislav
Copy link
Contributor

mislav commented Jul 17, 2015

Ah, I see now. You're passing a Request to a Request constructor. I don't think we support that case yet. Thanks for reporting.

@cesarandreu
Copy link
Author

@mislav could we get a new release of whatwg-fetch :D?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants