question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Server-sent events explicitly requires --stream

See original GitHub issue

If I have a server-sent event source and try to simply do

http get http://localhost:1729/stream/all

I get output that looks something like this:

HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Type: text/event-stream
Date: Sat, 29 Aug 2015 12:18:00 GMT
Server: TornadoServer/4.2.1
Transfer-Encoding: chunked

followed by none of the streamed data. This can be worked around by setting the --stream flag. However, better behavior would be to automatically enable streaming support when Content-Type is text/event-stream.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:12
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rwishcommented, Jun 27, 2017

Hi, I’m a newbie to open source projects. I would like to contribute to make HTTPie to automatically recognize server sent events. Could you please provide me with more info and can I work on this issue?

1reaction
sigmavirus24commented, Aug 29, 2015

Actually, the best behaviour is to auto-enable --stream when you see Transfer-Encoding: chunked because the length is indeterminate. That said, this is going to be near impossible to do for httpie. An example of what httpie is doing under the covers is

import requests
r = requests.get('http://localhost:1729/stream/all')
print_headers(r)
print_body(r)

What it does with --stream is:

import requests
r = requests.get('http://localhost:1729/stream/all', stream=True)
print_headers(r)
print_body(r)

This means that by the time httpie has received the headers it’s too late to begin streaming. httpie would need to perform a HEAD request for every URL to determine whether or not to automatically enable --stream for the user which would be wildly inefficient. While this is certainly a desirable feature, I’m not sure it’s practical.

The one way to acommodate this would be for httpie to always pass stream=True to requests and if --stream isn’t provided and the headers aren’t something that should require streaming, then it reads the whole content into memory (accessing the content attribute will take care of that). Otherwise, it streams appropriately.

I’m not sure if @jkbrzt wants httpie to absorb some logic from it’s dependencies though just to perform some magic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Harness the power of Server-Sent Events (SSE) in Node.js ...
1. Create a uni-directional connection (server to client) using the '/events' route that creates an event stream connection with the client.
Read more >
Server-sent events: a simple way to stream events from a server
Here's how server-sent events work. I was SO DELIGHTED to learn that they're just HTTP requests. ... The wire protocol is really simple...
Read more >
A Look at Server Sent Events | simonprickett.dev
Server Sent Events are a standard allowing browser clients to receive a stream of updates from a server over a HTTP connection without...
Read more >
What Server-Sent Events is - and how and when to implement it
The idea is simple: a browser can subscribe to a stream of events generated by a server, receiving updates whenever a new event...
Read more >
Browser APIs and Protocols: Server-Sent Events (SSE)
To get started, we simply need to specify the URL of the SSE event stream resource and register the ... Subscribe to all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found