-
Notifications
You must be signed in to change notification settings - Fork 1
Description
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.