-
I have a body with JSON lines that takes seconds to generate. I can formulate it as a StreamBody, but I would like to flush the output occasionally in order to keep the client's time-to-first-byte low. futures::stream::Stream does not have a mechanism to "push" data. It does not seem possible to flush streamed data in the current version of Axum? Is there any other way (short of forcing clients to switch to websockets) to encourage Axum to send data early? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
No I don't think so. I'm not quite sure how it works at the lower levels of the network stack but afaik no data is sent (depending on internal buffer sizes in the TCP stack maybe) until the client requests it. |
Beta Was this translation helpful? Give feedback.
-
Interestingly, some low-level component reacts to newline. Adding a |
Beta Was this translation helpful? Give feedback.
Interestingly, some low-level component reacts to newline. Adding a
write!(buf, "\n")?
in the stream triggers a flush. This is regardless of whether the content type istext/*
or not. It solves my problem, tho.