mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Don't use decode_packet/3 for parsing the request-line
First step in making all methods and header names binaries to get rid of many inconsistencies caused by decode_packet/3. Methods are all binary now. Note that since they are case sensitive, the usual methods become <<"GET">>, <<"POST">> and so on.
This commit is contained in:
parent
f6791b008a
commit
8497c8bbcd
10 changed files with 147 additions and 107 deletions
|
@ -16,9 +16,9 @@ handle(Req, State) ->
|
|||
{ok, Req4} = echo(Method, Echo, Req3),
|
||||
{ok, Req4, State}.
|
||||
|
||||
echo('GET', undefined, Req) ->
|
||||
echo(<<"GET">>, undefined, Req) ->
|
||||
cowboy_req:reply(400, [], <<"Missing echo parameter.">>, Req);
|
||||
echo('GET', Echo, Req) ->
|
||||
echo(<<"GET">>, Echo, Req) ->
|
||||
cowboy_req:reply(200,
|
||||
[{<<"Content-Encoding">>, <<"utf-8">>}], Echo, Req);
|
||||
echo(_, _, Req) ->
|
||||
|
|
|
@ -16,11 +16,11 @@ handle(Req, State) ->
|
|||
{ok, Req4} = maybe_echo(Method, HasBody, Req3),
|
||||
{ok, Req4, State}.
|
||||
|
||||
maybe_echo('POST', true, Req) ->
|
||||
maybe_echo(<<"POST">>, true, Req) ->
|
||||
{ok, PostVals, Req2} = cowboy_req:body_qs(Req),
|
||||
Echo = proplists:get_value(<<"echo">>, PostVals),
|
||||
echo(Echo, Req2);
|
||||
maybe_echo('POST', false, Req) ->
|
||||
maybe_echo(<<"POST">>, false, Req) ->
|
||||
cowboy_req:reply(400, [], <<"Missing body.">>, Req);
|
||||
maybe_echo(_, _, Req) ->
|
||||
%% Method not allowed.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue