Re: [whatwg/fetch] Fetch body streams are not full duplex (#1254)

> Does the specification also have such issues?

As far as I can tell, yes. The request body is sent synchronously before receiving response headers (not in parallel). See the "To transmit request’s body body, run these steps:" section in [HTTP-network fetch](https://fetch.spec.whatwg.org/#http-network-fetch) step 8.5. Essentially what needs to happen is, that this needs to be changed to happen in parallel with receiving the response headers.

> Now that you mention that example though I realize it is rather tricky if not impossible to do well here and be forward compatible.

To elaborate on this: many (likely most) web servers are programmed to only send back response headers after the request body has been received and processed (from now on referred to as category one servers). Because the promise returned from `fetch` would only resolve once the response headers are received. For the user the behaviour is that "fetch completes after the request body is fully sent". This behaviour would not change once full duplex streaming is implemented in browsers because the response headers are not received by the browser until the request body has been sent (because only then are they sent by the server).

For servers that send back response headers before the request body has been received (from now on referred to as category two servers), the promise returned from `fetch` would still only resolve once the request body is fully sent (because as you say, browsers do not support full duplex HTTP right now). Once browsers implement full duplex HTTP the promise returned from `fetch` would resolve after the response headers are received, regardless of the state of the request body. This is technically a minor change in behaviour, but one that could be marked as a spec compliance bug that Chrome, FF, and Safari have. The Deno or Servo implementations could implement full duplex right away.

Because the Python WPT test server probably falls into category one, the WPT I mentioned above is technically correct, but only under the assumption that the server sends headers after the response body is received. For cases where you need to handle both category one and category two servers you should handle the "cancellation" of the `ReadableStream`. This would be the only way to get notified of request body errors for category two servers.

--- 

TLDR, to solve this following would need to be resolved in the spec:

- [ ] Request body sending in _HTTP-network fetch_ should happen in parallel to waiting for response body headers.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/1254#issuecomment-862444219

Received on Wednesday, 16 June 2021 14:48:38 UTC