diff options
author | Loïc Hoguin <[email protected]> | 2015-05-05 19:59:37 +0300 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2015-05-05 19:59:37 +0300 |
commit | 228cebaf04f2c53b0bf09fb69b52be543cfc55ba (patch) | |
tree | b650dfde6e253aaee443883a1d277c56ac43c31e /src | |
parent | 90ae31998e8d0887b9efe4b441136ac047708bb9 (diff) | |
download | cowboy-228cebaf04f2c53b0bf09fb69b52be543cfc55ba.tar.gz cowboy-228cebaf04f2c53b0bf09fb69b52be543cfc55ba.tar.bz2 cowboy-228cebaf04f2c53b0bf09fb69b52be543cfc55ba.zip |
Add rfc7230 test suite and update others to recent Gun
This is a large commit.
The rfc7230 test suite adds many tests from the RFC7230 document.
Gun has been updated quite a bit recently, which broke the Cowboy
suites. This is now fixed with this commit.
A new hook onfirstrequest has been added. It was very useful during
debugging of the test suites.
The initial process code has changed a little; more changes are
expected with the switch to maps for options.
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_protocol.erl | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/src/cowboy_protocol.erl b/src/cowboy_protocol.erl index b1cdc3a..5a20f6b 100644 --- a/src/cowboy_protocol.erl +++ b/src/cowboy_protocol.erl @@ -75,25 +75,36 @@ get_value(Key, Opts, Default) -> -spec init(ranch:ref(), inet:socket(), module(), opts()) -> ok. init(Ref, Socket, Transport, Opts) -> - Compress = get_value(compress, Opts, false), - MaxEmptyLines = get_value(max_empty_lines, Opts, 5), - MaxHeaderNameLength = get_value(max_header_name_length, Opts, 64), - MaxHeaderValueLength = get_value(max_header_value_length, Opts, 4096), - MaxHeaders = get_value(max_headers, Opts, 100), - MaxKeepalive = get_value(max_keepalive, Opts, 100), - MaxRequestLineLength = get_value(max_request_line_length, Opts, 4096), - Middlewares = get_value(middlewares, Opts, [cowboy_router, cowboy_handler]), - Env = [{listener, Ref}|get_value(env, Opts, [])], - OnResponse = get_value(onresponse, Opts, undefined), - Timeout = get_value(timeout, Opts, 5000), ok = ranch:accept_ack(Ref), - wait_request(<<>>, #state{socket=Socket, transport=Transport, - middlewares=Middlewares, compress=Compress, env=Env, - max_empty_lines=MaxEmptyLines, max_keepalive=MaxKeepalive, - max_request_line_length=MaxRequestLineLength, - max_header_name_length=MaxHeaderNameLength, - max_header_value_length=MaxHeaderValueLength, max_headers=MaxHeaders, - onresponse=OnResponse, timeout=Timeout, until=until(Timeout)}, 0). + Timeout = get_value(timeout, Opts, 5000), + Until = until(Timeout), + case recv(Socket, Transport, Until) of + {ok, Data} -> + OnFirstRequest = get_value(onfirstrequest, Opts, undefined), + case OnFirstRequest of + undefined -> ok; + _ -> OnFirstRequest(Ref, Socket, Transport, Opts) + end, + Compress = get_value(compress, Opts, false), + MaxEmptyLines = get_value(max_empty_lines, Opts, 5), + MaxHeaderNameLength = get_value(max_header_name_length, Opts, 64), + MaxHeaderValueLength = get_value(max_header_value_length, Opts, 4096), + MaxHeaders = get_value(max_headers, Opts, 100), + MaxKeepalive = get_value(max_keepalive, Opts, 100), + MaxRequestLineLength = get_value(max_request_line_length, Opts, 4096), + Middlewares = get_value(middlewares, Opts, [cowboy_router, cowboy_handler]), + Env = [{listener, Ref}|get_value(env, Opts, [])], + OnResponse = get_value(onresponse, Opts, undefined), + parse_request(Data, #state{socket=Socket, transport=Transport, + middlewares=Middlewares, compress=Compress, env=Env, + max_empty_lines=MaxEmptyLines, max_keepalive=MaxKeepalive, + max_request_line_length=MaxRequestLineLength, + max_header_name_length=MaxHeaderNameLength, + max_header_value_length=MaxHeaderValueLength, max_headers=MaxHeaders, + onresponse=OnResponse, timeout=Timeout, until=Until}, 0); + {error, _} -> + terminate(#state{socket=Socket, transport=Transport}) %% @todo ridiculous + end. -spec until(timeout()) -> non_neg_integer() | infinity. until(infinity) -> |