Commit eada4dbc authored by Siebers, Michael's avatar Siebers, Michael
Browse files

endpoints requiring no body reply 408 on timeout

parent cce5ed38
......@@ -62,6 +62,8 @@ read_json_body_(Request, Payload) :-
% @throws invalid_header_value(content_length, Value) if a Content-Length header
% has been sent but the given value Value is invalid (no nonnegative
% integer).
% @throws `request_timeout` if discarded the body timed out (less bytes on the
% streem than promised by a Content-Length header).
purge_input_stream(Request) :-
memberchk(input(StreamIn), Request),
memberchk(content_length(Len), Request),
......@@ -69,13 +71,18 @@ purge_input_stream(Request) :-
integer(Len),
( Len >= 0
-> setup_call_cleanup(open_null_stream(StreamOut),
copy_stream_data(StreamIn, StreamOut, Len),
purge_input_stream_(StreamIn, StreamOut, Len),
close(StreamOut)
); throw(invalid_header_value(content_length, Len))
)
.
purge_input_stream(_).
purge_input_stream_(StreamIn, StreamOut, Len) :-
catch(copy_stream_data(StreamIn, StreamOut, Len),
error(timeout_error(read, _Stream),_),
throw(request_timeout)
).
%! parse_parameters(+In, ++Type, -Out) is det.
%
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment