1

After reviewing several HTTP implementations in Rust I realized that all of them seem to implement message body as "something to read". For example, all of these are used as both request AND response bodies:

Which means that when implementing a server endpoint, you are expected to provide a source of bytes that will be read whenever the server decides to read.

But what if you need to control how the body is written into the response stream; e.g., when individual chunks need to be flushed exactly when needed?

This is often required in order to implement something like Server-Sent Events or similar long-poll protocols.

May other language frameworks (like Go or Java) model server response bodies (as well as client request bodies) as "something to write" -- the implementation controls when to write and flush the bytes.

In Rust, and perhaps just those frameworks specifically, what is the reasoning for representing both request and response bodies as the same type/trait?

Is there an HTTP framework (preferably async/await friendly) that doesn't?

  • I am not sure what do you mean "something to read". Can you provide function or trait as an example? – Vadym Chekan Nov 22 '19 at 01:29
  • 1
    I am not sure I see the difference, to be honest. Specifically, there is no API guarantee in Go or Java that when you return a chunk it will be written in full, the framework could only flush every 4KB for example. And conversely, there is nothing that prevents a Rust framework not to try and flush anything appearing in the response stream as soon as possible. It seems more like an implementation detail than an API construct to me. – Matthieu M. Nov 22 '19 at 10:16

0 Answers0