aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-10-04 10:54:30 +0200
committerLoïc Hoguin <[email protected]>2011-10-04 10:54:30 +0200
commitd25c30790cc3afae03838a160f87ca0acd745989 (patch)
tree0f425a5fe6079f4140a72a87c3bc34fc6f6efbf2
parent986630d9ad70a1ae82954a7bfedc976a1b8b7294 (diff)
downloadcowboy-d25c30790cc3afae03838a160f87ca0acd745989.tar.gz
cowboy-d25c30790cc3afae03838a160f87ca0acd745989.tar.bz2
cowboy-d25c30790cc3afae03838a160f87ca0acd745989.zip
Do not send a 408 response if the Request-Line wasn't fully received
The server should not send a response if there wasn't at least the beginning of a request sent (the Request-Line).
-rw-r--r--src/cowboy_http_protocol.erl3
-rw-r--r--test/http_SUITE.erl18
2 files changed, 12 insertions, 9 deletions
diff --git a/src/cowboy_http_protocol.erl b/src/cowboy_http_protocol.erl
index 40dc51c..14cd8d3 100644
--- a/src/cowboy_http_protocol.erl
+++ b/src/cowboy_http_protocol.erl
@@ -87,8 +87,7 @@ wait_request(State=#state{socket=Socket, transport=Transport,
case Transport:recv(Socket, 0, T) of
{ok, Data} -> parse_request(State#state{
buffer= << Buffer/binary, Data/binary >>});
- {error, timeout} -> error_terminate(408, State);
- {error, closed} -> terminate(State)
+ {error, _Reason} -> terminate(State)
end.
-spec request({http_request, http_method(), http_uri(),
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl
index 813aa15..8bfebaa 100644
--- a/test/http_SUITE.erl
+++ b/test/http_SUITE.erl
@@ -197,10 +197,14 @@ raw_req(Packet, Config) ->
{ok, Socket} = gen_tcp:connect("localhost", Port,
[binary, {active, false}, {packet, raw}]),
ok = gen_tcp:send(Socket, Packet),
- {ok, << "HTTP/1.1 ", Str:24/bits, _Rest/bits >>}
- = gen_tcp:recv(Socket, 0, 6000),
+ Res = case gen_tcp:recv(Socket, 0, 6000) of
+ {ok, << "HTTP/1.1 ", Str:24/bits, _Rest/bits >>} ->
+ list_to_integer(binary_to_list(Str));
+ {error, Reason} ->
+ Reason
+ end,
gen_tcp:close(Socket),
- {Packet, list_to_integer(binary_to_list(Str))}.
+ {Packet, Res}.
raw(Config) ->
Tests = [
@@ -209,10 +213,10 @@ raw(Config) ->
{"Garbage\r\n\r\n", 400},
{"\r\n\r\n\r\n\r\n\r\n\r\n", 400},
{"GET / HTTP/1.1\r\nHost: dev-extend.eu\r\n\r\n", 400},
- {"", 408},
- {"\r\n", 408},
- {"\r\n\r\n", 408},
- {"GET / HTTP/1.1", 408},
+ {"", closed},
+ {"\r\n", closed},
+ {"\r\n\r\n", closed},
+ {"GET / HTTP/1.1", closed},
{"GET / HTTP/1.1\r\n", 408},
{"GET / HTTP/1.1\r\nHost: localhost", 408},
{"GET / HTTP/1.1\r\nHost: localhost\r\n", 408},