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

Provide a way to send neither Content-Length nor a chunked body #20

Open
edgar-bonet opened this issue Feb 6, 2022 · 0 comments
Open

Comments

@edgar-bonet
Copy link
Contributor

This is a feature request.

The send_head() method either sends a Content-Length header (if a valid length is provided), or enables chunked transfer encoding. It would be nice if it could be instructed to do neither.

Use case: Server-sent events (SSE) are a nice way to send a stream of messages to the client without requiring a request/response pair for each message. Although not as popular as WebSockets, SSE has the advantage of simplicity. Being plain HTTP, it is easier to implement on an HTTP server, as it doesn't require switching protocols. The framing overhead can be as small as 7 bytes per message:

/* This is a complete SSE message. */
conn->printf(conn, "data:%s\n\n", message_payload);

Even though SSE seems to work fine with chunked transfer encoding, using this encoding is not required, and is actually not recommended:

Authors are also cautioned that HTTP chunking can have unexpected negative effects on the reliability of this protocol, in particular if the chunking is done by a different layer unaware of the timing requirements. If this is a problem, chunking can be disabled for serving event streams.

Also, wrapping SSE with chunked transfer encoding amounts to redundant message framing, which practically doubles the framing overhead.

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

No branches or pull requests

1 participant