cloudflare / cloudflare/workerd
If pedantic_wpt is set, ensure Response.type is basic when required
- Dominant language
- C++
- Stars
- 8.7k
- Forks
- 739
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 174
Description
We have only a stub implementation of [`Response.type`](https://developer.mozilla.org/en-US/docs/Web/API/Response/type) because most of it is not relevant to the workers context. Most of the types relate to CORS.
Unless the type is `error`, we always return `null`:
```
// This relates to CORS, which doesn't apply on the edge -- see Request::Initializer::mode.
// In discussing with other runtime implementations that do not implement CORS, it was
// determined that only the `'default'` and `'error'` properties should be implemented.
kj::StringPtr getType() {
if (statusCode == 0) return "error"_kj;
return "default"_kj;
}
```
However, to pass more WPT tests we should return `basic` when conditions fit, or are at least close enough.
> [basic](https://developer.mozilla.org/en-US/docs/Web/API/Response/type#basic)
This applies in any of the following cases:
The request is same-origin.
The requested URL's scheme is [data:](https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data).
The request's [mode](https://developer.mozilla.org/en-US/docs/Web/API/Request/mode) is navigate or websocket.
With this type, all response headers are exposed except [Set-Cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie).
Contributor guide
Assessment
This issue has not been assessed yet.