diff options
author | Loïc Hoguin <[email protected]> | 2017-11-20 00:22:41 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2017-11-20 00:23:27 +0100 |
commit | 62bf505d33199e40c7db4ed76417b5651ddc1df3 (patch) | |
tree | 3ac62ada44b9f0e8d8b949203aec145137d60823 /src/cowboy_http.erl | |
parent | d7761b52592e4ca8192cf16498c7aaa3c71526ce (diff) | |
download | cowboy-62bf505d33199e40c7db4ed76417b5651ddc1df3.tar.gz cowboy-62bf505d33199e40c7db4ed76417b5651ddc1df3.tar.bz2 cowboy-62bf505d33199e40c7db4ed76417b5651ddc1df3.zip |
Add more rfc7230 tests
Also fixes the handling of the max_headers option for HTTP/1.1.
It is now a strict limit and not dependent on whether data is
already in the buffer.
Diffstat (limited to 'src/cowboy_http.erl')
-rw-r--r-- | src/cowboy_http.erl | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl index 62454ac..0c13ded 100644 --- a/src/cowboy_http.erl +++ b/src/cowboy_http.erl @@ -454,18 +454,24 @@ parse_header(Rest, State=#state{in_state=PS}, Headers) when byte_size(Rest) < 2 parse_header(<< $\r, $\n, Rest/bits >>, S, Headers) -> request(Rest, S, Headers); parse_header(Buffer, State=#state{opts=Opts, in_state=PS}, Headers) -> - MaxLength = maps:get(max_header_name_length, Opts, 64), MaxHeaders = maps:get(max_headers, Opts, 100), NumHeaders = maps:size(Headers), + if + NumHeaders >= MaxHeaders -> + error_terminate(431, State#state{in_state=PS#ps_header{headers=Headers}}, + {connection_error, limit_reached, + 'The number of headers is larger than configuration allows. (RFC7230 3.2.5, RFC6585 5)'}); + true -> + parse_header_colon(Buffer, State, Headers) + end. + +parse_header_colon(Buffer, State=#state{opts=Opts, in_state=PS}, Headers) -> + MaxLength = maps:get(max_header_name_length, Opts, 64), case match_colon(Buffer, 0) of nomatch when byte_size(Buffer) > MaxLength -> error_terminate(431, State#state{in_state=PS#ps_header{headers=Headers}}, {connection_error, limit_reached, 'A header name is larger than configuration allows. (RFC7230 3.2.5, RFC6585 5)'}); - nomatch when NumHeaders >= MaxHeaders -> - error_terminate(431, State#state{in_state=PS#ps_header{headers=Headers}}, - {connection_error, limit_reached, - 'The number of headers is larger than configuration allows. (RFC7230 3.2.5, RFC6585 5)'}); nomatch -> {more, State#state{in_state=PS#ps_header{headers=Headers}}, Buffer}; _ -> |