From 228cebaf04f2c53b0bf09fb69b52be543cfc55ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 5 May 2015 19:59:37 +0300 Subject: 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. --- src/cowboy_protocol.erl | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'src') 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) -> -- cgit v1.2.3