mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-15 04:30:25 +00:00
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).
This commit is contained in:
parent
986630d9ad
commit
d25c30790c
2 changed files with 12 additions and 9 deletions
|
@ -87,8 +87,7 @@ wait_request(State=#state{socket=Socket, transport=Transport,
|
||||||
case Transport:recv(Socket, 0, T) of
|
case Transport:recv(Socket, 0, T) of
|
||||||
{ok, Data} -> parse_request(State#state{
|
{ok, Data} -> parse_request(State#state{
|
||||||
buffer= << Buffer/binary, Data/binary >>});
|
buffer= << Buffer/binary, Data/binary >>});
|
||||||
{error, timeout} -> error_terminate(408, State);
|
{error, _Reason} -> terminate(State)
|
||||||
{error, closed} -> terminate(State)
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec request({http_request, http_method(), http_uri(),
|
-spec request({http_request, http_method(), http_uri(),
|
||||||
|
|
|
@ -197,10 +197,14 @@ raw_req(Packet, Config) ->
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", Port,
|
{ok, Socket} = gen_tcp:connect("localhost", Port,
|
||||||
[binary, {active, false}, {packet, raw}]),
|
[binary, {active, false}, {packet, raw}]),
|
||||||
ok = gen_tcp:send(Socket, Packet),
|
ok = gen_tcp:send(Socket, Packet),
|
||||||
{ok, << "HTTP/1.1 ", Str:24/bits, _Rest/bits >>}
|
Res = case gen_tcp:recv(Socket, 0, 6000) of
|
||||||
= gen_tcp:recv(Socket, 0, 6000),
|
{ok, << "HTTP/1.1 ", Str:24/bits, _Rest/bits >>} ->
|
||||||
|
list_to_integer(binary_to_list(Str));
|
||||||
|
{error, Reason} ->
|
||||||
|
Reason
|
||||||
|
end,
|
||||||
gen_tcp:close(Socket),
|
gen_tcp:close(Socket),
|
||||||
{Packet, list_to_integer(binary_to_list(Str))}.
|
{Packet, Res}.
|
||||||
|
|
||||||
raw(Config) ->
|
raw(Config) ->
|
||||||
Tests = [
|
Tests = [
|
||||||
|
@ -209,10 +213,10 @@ raw(Config) ->
|
||||||
{"Garbage\r\n\r\n", 400},
|
{"Garbage\r\n\r\n", 400},
|
||||||
{"\r\n\r\n\r\n\r\n\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},
|
{"GET / HTTP/1.1\r\nHost: dev-extend.eu\r\n\r\n", 400},
|
||||||
{"", 408},
|
{"", closed},
|
||||||
{"\r\n", 408},
|
{"\r\n", closed},
|
||||||
{"\r\n\r\n", 408},
|
{"\r\n\r\n", closed},
|
||||||
{"GET / HTTP/1.1", 408},
|
{"GET / HTTP/1.1", closed},
|
||||||
{"GET / HTTP/1.1\r\n", 408},
|
{"GET / HTTP/1.1\r\n", 408},
|
||||||
{"GET / HTTP/1.1\r\nHost: localhost", 408},
|
{"GET / HTTP/1.1\r\nHost: localhost", 408},
|
||||||
{"GET / HTTP/1.1\r\nHost: localhost\r\n", 408},
|
{"GET / HTTP/1.1\r\nHost: localhost\r\n", 408},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue