diff options
author | Ingela Anderton Andin <[email protected]> | 2017-10-12 11:55:30 +0200 |
---|---|---|
committer | Ingela Anderton Andin <[email protected]> | 2017-11-01 11:04:33 +0100 |
commit | eff478611df711b328fd5e349e1c937ea8be4b5b (patch) | |
tree | cd48a610ee1311b321d3d74cc01c2db0485fed0c /lib/inets/src | |
parent | 425b826e7fefe3bd4b174adfb8ead5953dd5dadf (diff) | |
download | otp-eff478611df711b328fd5e349e1c937ea8be4b5b.tar.gz otp-eff478611df711b328fd5e349e1c937ea8be4b5b.tar.bz2 otp-eff478611df711b328fd5e349e1c937ea8be4b5b.zip |
inets: httpd - Fix broken handling of POST requests
New chunk mechanism of body data in POST requests added in
5d01c70ca399edf28e99dc760506329689fab6ba
broke handling of POST body data not using the new mechanism.
Added better regression test
Diffstat (limited to 'lib/inets/src')
-rw-r--r-- | lib/inets/src/http_server/httpd_request.erl | 4 | ||||
-rw-r--r-- | lib/inets/src/http_server/httpd_request_handler.erl | 11 |
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/inets/src/http_server/httpd_request.erl b/lib/inets/src/http_server/httpd_request.erl index 0eaf073255..007d272323 100644 --- a/lib/inets/src/http_server/httpd_request.erl +++ b/lib/inets/src/http_server/httpd_request.erl @@ -306,10 +306,10 @@ add_chunk([<<>>, Body, Length, MaxChunk]) -> add_chunk([More, Body, Length, MaxChunk]) -> body_chunk(<<Body/binary, More/binary>>, Length, MaxChunk). -body_chunk(<<>> = Body, Length, MaxChunk) -> - {ok, {continue, ?MODULE, add_chunk, [Body, Length, MaxChunk]}}; body_chunk(Body, Length, nolimit) -> whole_body(Body, Length); +body_chunk(<<>> = Body, Length, MaxChunk) -> + {ok, {continue, ?MODULE, add_chunk, [Body, Length, MaxChunk]}}; body_chunk(Body, Length, MaxChunk) when Length > MaxChunk -> case size(Body) >= MaxChunk of diff --git a/lib/inets/src/http_server/httpd_request_handler.erl b/lib/inets/src/http_server/httpd_request_handler.erl index bd4fdd3832..d918f10424 100644 --- a/lib/inets/src/http_server/httpd_request_handler.erl +++ b/lib/inets/src/http_server/httpd_request_handler.erl @@ -516,6 +516,15 @@ handle_body(#state{headers = Headers, body = Body, case ((Length =< MaxBodySize) or (MaxBodySize == nolimit)) of true -> case httpd_request:body_chunk_first(Body, Length, MaxChunk) of + %% This is the case that the we need more data to complete + %% the body but chunking to the mod_esi user is not enabled. + {Module, add_chunk = Function, Args} -> + http_transport:setopts(ModData#mod.socket_type, + ModData#mod.socket, + [{active, once}]), + {noreply, State#state{mfa = + {Module, Function, Args}}}; + %% Chunking to mod_esi user is enabled {ok, {continue, Module, Function, Args}} -> http_transport:setopts(ModData#mod.socket_type, ModData#mod.socket, @@ -525,6 +534,8 @@ handle_body(#state{headers = Headers, body = Body, {ok, {{continue, Chunk}, Module, Function, Args}} -> handle_internal_chunk(State#state{chunk = chunk_start(MaxChunk), body = Chunk}, Module, Function, Args); + %% Whole body delivered, if chunking mechanism is enabled the whole + %% body fits in one chunk. {ok, NewBody} -> handle_response(State#state{chunk = chunk_finish(ChunkState, CbState, MaxChunk), |