From 8366ba94bb9e450221a246acdd482c0162affcd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 8 Apr 2015 23:34:08 +0300 Subject: Use maps for and improve options The type option has been removed. The transport and protocols options can be used in its place. The transport_opts option can be used to specify transport options. The http_opts and spdy_opts options can be used to specify protocol specific options. The keepalive option is now a protocol specific option. Defaults depending on the port number have changed. Now only port 443 uses ssl by default, other ports use tcp. --- src/gun_http.erl | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/gun_http.erl') diff --git a/src/gun_http.erl b/src/gun_http.erl index 745c2a9..4726f03 100644 --- a/src/gun_http.erl +++ b/src/gun_http.erl @@ -14,6 +14,7 @@ -module(gun_http). +-export([check_options/1]). -export([init/4]). -export([handle/2]). -export([close/1]). @@ -24,9 +25,6 @@ -export([cancel/2]). -export([ws_upgrade/7]). --type opts() :: [{version, cow_http:version()}]. --export_type([opts/0]). - -type io() :: head | {body, non_neg_integer()} | body_close | body_chunked. -type websocket_info() :: {websocket, reference(), binary(), [], []}. %% key, extensions, protocols @@ -44,11 +42,19 @@ out = head :: io() }). -init(Owner, Socket, Transport, []) -> - #http_state{owner=Owner, socket=Socket, transport=Transport}; -init(Owner, Socket, Transport, [{version, Version}]) -> - #http_state{owner=Owner, socket=Socket, transport=Transport, - version=Version}. +check_options(Opts) -> + do_check_options(map:to_list(Opts)). + +do_check_options([{keepalive, K}|Opts]) when is_integer(K), K > 0 -> + do_check_options(Opts); +do_check_options([{version, V}|Opts]) when V =:= 'HTTP/1.1'; V =:= 'HTTP/1.0' -> + do_check_options(Opts); +do_check_options([Opt|_]) -> + {error, {options, {http, Opt}}}. + +init(Owner, Socket, Transport, Opts) -> + Version = maps:get(version, Opts, 'HTTP/1.1'), + #http_state{owner=Owner, socket=Socket, transport=Transport, version=Version}. %% Stop looping when we got no more data. handle(<<>>, State) -> -- cgit v1.2.3