Skip to content

Instantly share code, notes, and snippets.

@majek
Created February 7, 2012 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save majek/1760599 to your computer and use it in GitHub Desktop.
Save majek/1760599 to your computer and use it in GitHub Desktop.
cowboy http/1.0 bug
#!/usr/bin/env escript
%%! -smp disable +A1 +K true -pz ./ebin -pa deps/cowboy/ebin -input
-module(cowboy_http10_bug).
-mode(compile).
-export([main/1]).
%% Cowboy callbacks
-export([init/3, handle/2, terminate/2]).
main(_) ->
Port = 9999,
application:start(cowboy),
VhostRoutes = [{'_', ?MODULE, []}],
Routes = [{'_', VhostRoutes}],
cowboy:start_listener(http, 100,
cowboy_tcp_transport, [{port, Port}],
cowboy_http_protocol, [{dispatch, Routes}]),
io:format(" [*] Running at http://localhost:~p~n", [Port]),
receive
_ -> ok
end.
%% --------------------------------------------------------------------------
init({_Any, http}, Req, []) ->
{ok, Req, []}.
handle(Req, State) ->
{ok, Req1} = cowboy_http_req:chunked_reply(200, [], Req),
_ = cowboy_http_req:chunk(<<"ok">>, Req1),
{ok, Req1, State}.
terminate(_Req, _State) ->
ok.
GET /blah HTTP/1.0
Host: localhost:9999
Accept-Encoding: identity
Content-Length: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment