Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support auto-enable --stream when meet server sent events #204

Closed
daleione opened this issue Dec 1, 2021 · 5 comments · Fixed by #360
Closed

Support auto-enable --stream when meet server sent events #204

daleione opened this issue Dec 1, 2021 · 5 comments · Fixed by #360

Comments

@daleione
Copy link

daleione commented Dec 1, 2021

#httpie/cli#376

@ducaale
Copy link
Owner

ducaale commented Dec 1, 2021

I think httpie/cli#376 (comment) is something we can implement easily in xh:

Actually, the best behaviour is to auto-enable --stream when you see Transfer-Encoding: chunked because the length is indeterminate.

@blyxxyz
Copy link
Collaborator

blyxxyz commented Dec 1, 2021

I don't think that's right. Nginx sends me Transfer-Encoding: chunked for a static page, and Flask doesn't send it when I have an endpoint that yields lines at one-second intervals.

There are apparently other mimetypes for streaming besides text/event-stream. But we shouldn't just check whether it has the word "stream" in it, application/octet-stream is the usual fallback for binary data.

It might actually make sense to just always enable streaming. The encoding detection and the binary content detection would suffer but I'm not sure anything else would. I haven't thought about it for very long though.

@ducaale
Copy link
Owner

ducaale commented Dec 2, 2021

It might actually make sense to just always enable streaming. The encoding detection and the binary content detection would suffer but I'm not sure anything else would. I haven't thought about it for very long though.

Do you know if enabling streaming comes with any noticeable performance degradation?

@blyxxyz
Copy link
Collaborator

blyxxyz commented Dec 2, 2021

Hmm. It seems that writing formatted JSON is much slower when streaming because the output isn't buffered. That's probably fixable by adding buffering but flushing it after each read (to make sure there's no delay).

There might be other cases.

@ducaale
Copy link
Owner

ducaale commented Feb 12, 2022

As of HTTPie 3.0, --stream is enabled if content-type equals text/event-stream. See httpie/cli#1226

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants