diff options
author | Loïc Hoguin <[email protected]> | 2017-09-25 12:34:44 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2017-09-25 12:48:47 +0200 |
commit | c09b10190baaae37f4de8bc1732d79acca62b53d (patch) | |
tree | ac6372b69cd36e20330531361896a86632ac4ab7 /src/cowboy_http.erl | |
parent | a6126306a2b9e956c38b10e8cf1e60acdb4e63fe (diff) | |
download | cowboy-c09b10190baaae37f4de8bc1732d79acca62b53d.tar.gz cowboy-c09b10190baaae37f4de8bc1732d79acca62b53d.tar.bz2 cowboy-c09b10190baaae37f4de8bc1732d79acca62b53d.zip |
Move body length count to cowboy_stream_h instead of protocols
The documentation was correct, the code was not.
This should make it easier to implement new protocols. Note that
for HTTP/2 we will need to add some form of counting later on to
check for malformed requests, but we can do simpler and just
reduce from the expected length and then check if that's 0 when
IsFin=fin.
Diffstat (limited to 'src/cowboy_http.erl')
-rw-r--r-- | src/cowboy_http.erl | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl index 107fd60..f0f8ed7 100644 --- a/src/cowboy_http.erl +++ b/src/cowboy_http.erl @@ -709,11 +709,13 @@ parse_body(Buffer, State=#state{in_streamid=StreamID, in_state= %% @todo Asks for 0 or more bytes. {data, StreamID, nofin, Data, State#state{in_state= PS#ps_body{transfer_decode_state=TState}}, Rest}; - {done, TotalLength, Rest} -> - {data, StreamID, {fin, TotalLength}, <<>>, set_timeout( + %% @todo We probably want to confirm that the total length + %% is the same as the content-length, if one was provided. + {done, _TotalLength, Rest} -> + {data, StreamID, fin, <<>>, set_timeout( State#state{in_streamid=StreamID + 1, in_state=#ps_request_line{}}), Rest}; - {done, Data, TotalLength, Rest} -> - {data, StreamID, {fin, TotalLength}, Data, set_timeout( + {done, Data, _TotalLength, Rest} -> + {data, StreamID, fin, Data, set_timeout( State#state{in_streamid=StreamID + 1, in_state=#ps_request_line{}}), Rest} end. |