Skip to content

Commit

Permalink
protocol tweaks
Browse files Browse the repository at this point in the history
- allow PUT as an HTTP verb
- as per RFC2616, trailing CRLF is disallowed.
  • Loading branch information
evanmcc committed Sep 13, 2017
1 parent 311d135 commit 956521a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/buoy_protocol.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ request(Method, Path, Headers, Host, undefined) ->
<<"Host: ">>, Host,
<<"\r\nConnection: Keep-alive\r\n">>,
<<"User-Agent: buoy\r\n">>,
format_headers(Headers), <<"\r\n">>];
format_headers(Headers)];
request(Method, Path, Headers, Host, Body) ->
ContentLength = integer_to_binary(iolist_size(Body)),
Headers2 = [{<<"Content-Length">>, ContentLength} | Headers],
Expand All @@ -55,7 +55,7 @@ request(Method, Path, Headers, Host, Body) ->
<<"\r\nConnection: Keep-alive\r\n">>,
<<"User-Agent: buoy\r\n">>,
format_headers(Headers2), <<"\r\n">>,
Body, <<"\r\n">>].
Body].

-spec response(binary()) ->
{ok, buoy_resp(), binary()} | error().
Expand Down Expand Up @@ -134,7 +134,9 @@ content_length([_ | T]) ->
format_method(get) ->
<<"GET">>;
format_method(post) ->
<<"POST">>.
<<"POST">>;
format_method(put) ->
<<"PUT">>.

format_headers(Headers) ->
[format_header(Header) || Header <- Headers].
Expand Down
4 changes: 2 additions & 2 deletions test/buoy_protocol_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ request_test() ->
Request = buoy_protocol:request(get, <<"/">>, [],
<<"127.0.0.1:8080">>, undefined),
?assertEqual(<<"GET / HTTP/1.1\r\nHost: 127.0.0.1:8080\r\n",
"Connection: Keep-alive\r\nUser-Agent: buoy\r\n\r\n">>,
"Connection: Keep-alive\r\nUser-Agent: buoy\r\n">>,
iolist_to_binary(Request)),

Request2 = buoy_protocol:request(post, <<"/">>, [],
<<"127.0.0.1:8080">>, <<"Hello World!">>),
?assertEqual(<<"POST / HTTP/1.1\r\nHost: 127.0.0.1:8080\r\n",
"Connection: Keep-alive\r\nUser-Agent: buoy\r\n",
"Content-Length: 12\r\n\r\nHello World!\r\n">>,
"Content-Length: 12\r\n\r\nHello World!">>,
iolist_to_binary(Request2)).

response_test_() -> [
Expand Down

0 comments on commit 956521a

Please sign in to comment.