Skip to content

Commit

Permalink
Merge pull request #98 from jeffgrunewald/export_additional_funcs
Browse files Browse the repository at this point in the history
Exposing additional functions for external use
  • Loading branch information
yurrriq authored Jan 19, 2021
2 parents dd1a76f + 7c8535c commit 05e24b1
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/elli_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@

-export([send_response/4]).

-export([send_file/5]).

-export([mk_req/8, mk_req/11]). %% useful when testing.

%% Exported for looping with a fully-qualified module name
-export([accept/4, handle_request/4, chunk_loop/1, split_args/1,
parse_path/1, keepalive_loop/3, keepalive_loop/5]).

%% Exported for correctly handling session keep-alive for handlers
%% operating in handler mode.
-export([close_or_keepalive/2]).

-export_type([version/0]).

%% @type version(). HTTP version as a tuple, i.e. `{0, 9} | {1, 0} | {1, 1}'.
Expand Down Expand Up @@ -668,14 +674,15 @@ connection_token(#req{version = {1, 0}, headers = Headers}) ->
connection_token(#req{version = {0, 9}}) ->
<<"close">>.


%% @doc Return the preferred session handling setting to close or keep the
%% current session alive based on the presence of a header or the standard
%% default based on the version of HTTP of the request.
-spec close_or_keepalive(Req, Headers) -> KeepaliveOpt when
Req :: elli:req(),
Headers :: elli:headers(),
KeepaliveOpt :: close | keep_alive.
close_or_keepalive(Req, UserHeaders) ->
case get_header(?CONNECTION_HEADER, UserHeaders) of
undefined ->
case connection_token(Req) of
<<"Keep-Alive">> -> keep_alive;
<<"close">> -> close
end;
case get_header(?CONNECTION_HEADER, UserHeaders, connection_token(Req)) of
<<"close">> -> close;
<<"Keep-Alive">> -> keep_alive
end.
Expand Down

0 comments on commit 05e24b1

Please sign in to comment.