- Notifications
You must be signed in to change notification settings - Fork352
AddResponse.json
static method#1392
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This commit adds a `Response.json` static method that can be used tocreate well formed JSON responses will very little effort.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Note that we'd need to fix Web IDL first to allow regular and static operations with the same name:
|
@domenic Do you think that is desirable to change? It may be confusing to have both a prototype and static method with the same name. Maybe this method should be called |
I think it is desirable to change and do not see anything confusing about having such methods, personally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This looks reasonable, but I think it can be improved by making initialize a response also take a body and Content-Type header value (potentially as a tuple?). That would allow for sharing even more steps.
I also wonder what we should do here if browser interest isn't forthcoming. Perhaps there's a way in which we can still have mutual agreement, but it's not exposed in browsers for now. Perhaps this is worth bringing up in the HTML triage call (if it doesn't otherwise get resolved).
jasnell commentedMar 8, 2022
Just fyi... I have an implementation of this in Cloudflare Workers just waiting on this to land or at least signal that it's moving forward. |
domenic commentedMar 8, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I don't think we have any signal that this is moving forward in browsers, unfortunately, due to it just being low-priority sugar for browser teams. As such I don't think it'll land in Fetch, at least until a couple of browsers have engineers looking for starter projects. I'd really encourage you to use this as a case study forhttps://github.com/whatwg/js-hosts . Figure out what sort of documentation you want to create there, which would enable you to land such things with confidence, and go for it! I'm happy to participate and secure guarantees like "Chromium will never ship a |
@domenic Would this get a 👍 from Chromium if we did the implementation work? |
@ricea would be the decider there but I can predict with very high probability he would support it :). |
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Mostly nits and request for a follow-up. Shared algorithm looks rather good! Thanks.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yeah I know, it's just sad and mostly a consequence of some early ideas aroundtext/*
that ended up not mattering (at least not on the web).
Anyway, thanks for all your hard work on this. This was not an easy feature given all the work on Web IDL, refactoring of various Fetch algorithms, etc. 😊
I suggest we give folks until May 18 to voice any remaining concerns and merge it that day sometime.
This change isn't possible to roll into WPT's idlharness.js test, seeweb-platform-tests/wpt#34155. Does anyone want to give it a go to update idlharness.js to avoid this problem? |
…stonlyAutomatic update from web-platform-testsFetch: add tests for Response.jsonContext:whatwg/fetch#1392.--wpt-commits: 27e770bcfbeae534b5d4cbc0a50d2b8247942312wpt-pr: 32825
…stonlyAutomatic update from web-platform-testsFetch: add tests for Response.jsonContext:whatwg/fetch#1392.--wpt-commits: 27e770bcfbeae534b5d4cbc0a50d2b8247942312wpt-pr: 32825
This commit adds support for the `Response.json` static method asspecified inwhatwg/fetch#1392.All WPTs fromweb-platform-tests/wpt#32825 pass.Bug:1305358Change-Id: Iaafdd514ed12644b6433c02e7d076ce43f51b9efReviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/3639064Reviewed-by: Yutaka Hirano <yhirano@chromium.org>Reviewed-by: Adam Rice <ricea@chromium.org>Commit-Queue: Yutaka Hirano <yhirano@chromium.org>Cr-Commit-Position: refs/heads/main@{#1019479}
https://bugs.webkit.org/show_bug.cgi?id=240375Reviewed by Youenn Fablet.This implements the `Response.json` static method, added to the fetchspec inwhatwg/fetch#1392.* LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-json.any-expected.txt:* LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-json.any.serviceworker-expected.txt:* LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-json.any.sharedworker-expected.txt:* LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-json.any.worker-expected.txt:* Source/WebCore/Modules/fetch/FetchBody.h:* Source/WebCore/Modules/fetch/FetchResponse.cpp:(WebCore::FetchResponse::create): Added this method overload to implement the spec's "initialize a response" algorithm. This algortihm used to be combined with the regular Response creation algorithm which extracts the body, but Response.json cannot use that directly.(WebCore::FetchResponse::staticJson):* Source/WebCore/Modules/fetch/FetchResponse.h:* Source/WebCore/Modules/fetch/FetchResponse.idl:Canonical link:https://commits.webkit.org/261960@main
Uh oh!
There was an error while loading.Please reload this page.
This commit adds a
Response.json
static method that can be used tocreate well formed JSON responses will very little effort.
The JSON response isnot pretty printed.
Closes#1389
Response.json()
denoland/deno#13902Preview |Diff