From ee8c50c5ab97dcaebc8932d093741fdb496e00f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sun, 29 Apr 2012 01:20:24 +0200 Subject: Fix and rework the HTTP test suite Use a proper HTTP client to run all tests. This client is currently undocumented and should not be used. Includes a few fixes: * Fix a bug in the max_keepalive test * Fix a bug with max_keepalive handling * Fix a bug in stream_body/1 where data was lost under some conditions The tests now run quite faster than before. All the tests now run twice: once for TCP, once for SSL. --- src/cowboy_http_req.erl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/cowboy_http_req.erl') diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl index a6e8834..dfb73e7 100644 --- a/src/cowboy_http_req.erl +++ b/src/cowboy_http_req.erl @@ -456,10 +456,11 @@ stream_body(Req=#http_req{body_state=done}) -> -spec stream_body_recv(#http_req{}) -> {ok, binary(), #http_req{}} | {error, atom()}. -stream_body_recv(Req=#http_req{transport=Transport, socket=Socket}) -> +stream_body_recv(Req=#http_req{ + transport=Transport, socket=Socket, buffer=Buffer}) -> %% @todo Allow configuring the timeout. case Transport:recv(Socket, 0, 5000) of - {ok, Data} -> transfer_decode(Data, Req); + {ok, Data} -> transfer_decode(<< Buffer/binary, Data/binary >>, Req); {error, Reason} -> {error, Reason} end. @@ -477,7 +478,7 @@ transfer_decode(Data, Req=#http_req{ {stream, TransferDecode, TransferState2, ContentDecode}}); %% @todo {header(s) for chunked more -> - stream_body_recv(Req); + stream_body_recv(Req#http_req{buffer=Data}); {done, Length, Rest} -> Req2 = transfer_decode_done(Length, Rest, Req), {done, Req2}; -- cgit v1.2.3