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 for streamed response from chunked_reply when writing to non-compliant clients #548

Closed
wants to merge 6 commits into from

Conversation

adrianroe
Copy link
Contributor

This was #471

As discussed, a revised approach that changes chunked_reply behaviour if the user first set resp_state to waiting_streaming

> compatibility with older clients. You can also force
> HTTP/1.0-like behaviour by calling
> `cowboy_req:set([{resp_state, waiting_streaming}], Req)`,
> to allow compatability with some non-compliant clients.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we don't want it documented. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reasonably sure :) waiting_stream is set in the handler using cowboy_req:set- see test/http_SUITE_data/http_streamed.erl for an example (copied below) - it's called in the streamed_response test in the http_SUITE

%% Feel free to use, reuse and abuse the code in this file.

-module(http_streamed).
-behaviour(cowboy_http_handler).
-export([init/3, handle/2, terminate/3]).

init({_Transport, http}, Req, _Opts) ->
{ok, Req, undefined}.

handle(Req, State) ->
Req2 = cowboy_req:set([{resp_state, waiting_stream}], Req),
{ok, Req3} = cowboy_req:chunked_reply(200, Req2),
timer:sleep(100),
cowboy_req:chunk("streamed_handler\r\n", Req3),
timer:sleep(100),
cowboy_req:chunk("works fine!", Req3),
{ok, Req3, State}.

terminate(_, _, _) ->
ok.

Dr Adrian Roe
Director

On Saturday, 29 June 2013 at 18:45, Loïc Hoguin wrote:

In manual/cowboy_req.md (http://cowboy_req.md):

@@ -443,7 +443,10 @@ Response related exports > > > > If the request uses HTTP/1.0, the data is sent directly > > without wrapping it in an HTTP/1.1 chunk, providing > -> compatibility with older clients. > +> compatibility with older clients. You can also force > +> HTTP/1.0-like behaviour by calling > +> cowboy_req:set([{resp_state, waiting_streaming}], Req), > +> to allow compatability with some non-compliant clients.
No we don't want it documented. :)


Reply to this email directly or view it on GitHub (https://github.com/extend/cowboy/pull/548/files#r4952576).

@essen
Copy link
Member

essen commented Jun 29, 2013

A few small comments, otherwise I'd rename waiting_streaming into waiting_stream, and streaming into stream. Also the indentation needs fixing (4-width tabs and no alignment please).

@essen
Copy link
Member

essen commented Aug 10, 2013

Are you sure this works? I don't see anywhere the waiting_stream state being set.

@essen
Copy link
Member

essen commented Nov 8, 2013

I've fixed a few more things, rebased into one commit c2e9467 and pushed. Closing, thanks!

@essen essen closed this Nov 8, 2013
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 this pull request may close these issues.

None yet

2 participants