-
Notifications
You must be signed in to change notification settings - Fork 339
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
Clarify whether fetch method and Request accept URL instances #452
Comments
Welkom! Part of the behavior of the API is defined through IDL. So https://fetch.spec.whatwg.org/#requestinfo is indeed either a Going to tentatively close this, but I'll happily respond to any further queries. |
Thanks for explaining! I guess we will have to tweak our polyfill to match this behavior. I wasn't aware that this conversion happens at the binding layer (I have little familiarity with IDL). But, the end behavior makes sense to me. |
See https://heycam.github.io/webidl/#es-USVString and how https://heycam.github.io/webidl/#dfn-overload-resolution-algorithm handles strings near the end for the full details, but beware, it's rather involved. |
This aims to match the behavior that the IDL of the spec defines: whatwg/fetch#452 (comment)
This aims to match the behavior that the IDL of the spec defines: whatwg/fetch#452 (comment)
This aims to match the behavior that the IDL of the spec defines: whatwg/fetch#452 (comment)
A URL instance is a valid argument to `fetch(url)` and `new Request(url)`. It's not mentioned explicitly in the spec: typedef (Request or USVString) RequestInfo; But, technically, any non-Request object that implements `toString()` is a valid argument, since it will be converted into string: whatwg/fetch#452 (comment) However, I didn't want to allow `any` as a type for RequestInfo, since that basically eliminates the benefit of typechecking the first argument. I'm not sure what the best approach to this would be, so in the meantime I have just added "URL" to the RequestInfo union.
This aims to match the behavior that the IDL of the spec defines: whatwg/fetch#452 (comment)
In
fetch(url)
andnew Request(url)
invocations, canurl
be an instance ofURL
? The spec is not clear.This example shows that
fetch()
should likely accept URL:However, when I look at the spec itself, the first argument for Request constructor is defined as "RequestInfo", and later on it states:
This suggests that the argument may only be "USVString" or Request, and that behavior concerning other types is undefined, or—as I interpret it—that any non-string type will be treated as Request and that an exception will be thrown if the type doesn't look like a Request.
The spec also suggests that the behavior of the
fetch()
method is identical tonew Request()
because the arguments tofetch()
are forwarded to Request constructor. It follows thatfetch()
too only accepts string or Request as argument.Google Chrome's implementation, however, seems to treat any non-Request argument as a url by converting it to a string. Example:
The text was updated successfully, but these errors were encountered: