You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As you can see, I have implemented trailer extension for http/2... but with some tricks. According to h2's document
When acting as a server, you may call ``send_headers`` any number of
times allowed by the following rules, in this order:
- zero or more times with ``(':status', '1XX')`` (where ``1XX`` is a
placeholder for any 100-level status code).
- once with any other status header.
- zero or one time for trailers.
So h2 will force to close stream when build trailers. When stream got closed, there is no chance to send that trailer. So you must flush that trailer immediately, then the stream is close. But wait, where is the response body? It's still waiting for http/2's priority! And since the stream is closed, you will lose the chance to send the response body. So the server must know which body should also be flushed without waiting for priority. How? Emm..... I added a extra key to do that, called meta. And by using await send({"type": "http.response.body", "body": xxxx, "meta": {"flush": True}}), the server will flush it without waiting. Using this method, I built a gRPC server, and successfully talked to a normal gRPC client. It's just.... that's not a part of asgi spec.
The text was updated successfully, but these errors were encountered:
Suddenly I came up with an idea: why not look into the headers? If trailer header exists in headers, then server just prepare to flush, in this case, we can throw meta field away
So, according to the comments in asgiref so far, now we have a trailer: bool key in http.response.start, maybe that could be used to determin whether to flush.
As you can see, I have implemented trailer extension for http/2... but with some tricks. According to h2's document
So h2 will force to close stream when build trailers. When stream got closed, there is no chance to send that trailer. So you must flush that trailer immediately, then the stream is close. But wait, where is the response body? It's still waiting for http/2's priority! And since the stream is closed, you will lose the chance to send the response body. So the server must know which body should also be flushed without waiting for priority. How? Emm..... I added a extra key to do that, called
meta
. And by usingawait send({"type": "http.response.body", "body": xxxx, "meta": {"flush": True}})
, the server will flush it without waiting. Using this method, I built a gRPC server, and successfully talked to a normal gRPC client. It's just.... that's not a part of asgi spec.The text was updated successfully, but these errors were encountered: