Browse Source

ft: 代码修改

master
SisMaker 3 years ago
parent
commit
45cc9eef9e
12 changed files with 55 additions and 576 deletions
  1. +12
    -28
      include/eWSrv.hrl
  2. +18
    -1
      include/wsCom.hrl
  3. +0
    -42
      src/example/wsEgHandover.erl
  4. +13
    -141
      src/example/wsEgHer.erl
  5. +0
    -26
      src/example/wsEgMiddleware.erl
  6. +9
    -31
      src/wsSrv/wsHer.erl
  7. +1
    -1
      src/wsSrv/wsHttp.erl
  8. +0
    -151
      src/wsSrv/wsMiddleware.erl
  9. +0
    -57
      src/wsSrv/wsMiddlewareCompress.erl
  10. +1
    -70
      src/wsSrv/wsNet.erl
  11. +0
    -27
      src/wsSrv/wsReq.erl
  12. +1
    -1
      src/wsSrv/wsSendFile.erl

+ 12
- 28
include/eWSrv.hrl View File

@ -1,22 +1,6 @@
-include_lib("eNet/include/eNet.hrl").
%% @type version(). HTTP version as a tuple, i.e. `{0, 9} | {1, 0} | {1, 1}'.
-type version() :: {0, 9} | {1, 0} | {1, 1}.
-export_type([version/0]).
-define(DefWsOpts, [
binary
, {packet, 4}
, {active, false}
, {reuseaddr, true}
, {nodelay, false}
, {delay_send, true}
, {send_timeout, 15000}
, {keepalive, true}
, {exit_on_close, true}
, {back_log, 1024}
]).
-export_type([wsOpt/0]).
-type wsOpt() ::
@ -35,27 +19,27 @@
body = <<>> :: body()
}).
-export_type([wsReq/0, method/0, body/0, headers/0, response_code/0]).
-export_type([
wsReq/0
, method/0
, body/0
, path/0
, headers/0
, httpCode/0
, version/0
]).
%% @type req(). A record representing an HTTP request.
-type wsReq() :: #wsReq{}.
%% @type http_method(). An uppercase atom representing a known HTTP verb or a
%% binary for other verbs.
-type method() :: 'OPTIONS' | 'GET' | 'HEAD' | 'POST'| 'PUT' | 'DELETE' | 'TRACE' | binary().
%% @type body(). A binary or iolist.
-type body() :: binary() | iolist().
-type path() :: binary().
-type header() :: {Key :: binary(), Value :: binary() | string()}.
-type headers() :: [header()].
-type response_code() :: 100..999.
-type httpCode() :: 100..999.
-type version() :: {0, 9} | {1, 0} | {1, 1}.
-define(CONTENT_LENGTH_HEADER, 'Content-Length').
-define(EXPECT_HEADER, <<"expect">>).
-define(CONNECTION_HEADER, 'Connection').
-define(TRANSFER_ENCODING_HEADER, <<"Transfer-Encoding">>).
-type sendfile_opts() :: [{chunk_size, non_neg_integer()}].

+ 18
- 1
include/wsCom.hrl View File

@ -6,11 +6,28 @@
-define(wsInfo(Format, Args), error_logger:info_msg(Format, Args)).
-define(wsGLV(Key, List, Default), wsUtil:gLV(Key, List, Default)).
-define(DefWsOpts, [
binary
, {packet, 4}
, {active, false}
, {reuseaddr, true}
, {nodelay, false}
, {delay_send, true}
, {send_timeout, 15000}
, {keepalive, true}
, {exit_on_close, true}
, {back_log, 1024}
]).
-define(IIF(Cond, Then, That), case Cond of true -> Then; _ -> That end).
-type stage() :: reqLine | header | body | done. %% http请求可能会有多个包
-export_type([
sendfile_opts/0
]).
-type sendfile_opts() :: [{chunk_size, non_neg_integer()}].
-type stage() :: reqLine | header | body | done. %% http请求可能会有多个包
-record(wsState, {
stage = reqLine :: stage() %%
, buffer = <<>> :: binary() %%

+ 0
- 42
src/example/wsEgHandover.erl View File

@ -1,42 +0,0 @@
-module(wsEgHandover).
-export([init/2, handle/2, handle_event/3]).
-include("wsCom.hrl").
-behaviour(wsHer).
%% @doc Return `{ok, handover}' if `Req''s path is `/hello/world',
%% otherwise `ignore'.
init(Req, _Args) ->
case wsReq:path(Req) of
[<<"hello">>, <<"world">>] ->
{ok, handover};
_ ->
ignore
end.
%% TODO: write docstring
-spec handle(Req, Args) -> Result when
Req :: elli:wsReq(),
Args :: wsHer:callback_args(),
Result :: wsHer:result().
handle(Req, Args) ->
handle(wsReq:method(Req), wsReq:path(Req), Req, Args).
handle('GET', [<<"hello">>, <<"world">>], Req, _Args) ->
Body = <<"Hello World!">>,
Size = integer_to_binary(size(Body)),
Headers = [{"Connection", "close"}, {"Content-Length", Size}],
wsHttp:send_response(Req, 200, Headers, Body),
{close, <<>>};
handle('GET', [<<"hello">>], Req, _Args) ->
%% Fetch a GET argument from the URL.
Name = wsReq:get_arg(<<"name">>, Req, <<"undefined">>),
{ok, [], <<"Hello ", Name/binary>>}.
%% @hidden
handle_event(_, _, _) ->
ok.

+ 13
- 141
src/example/wsEgHer.erl View File

@ -1,33 +1,17 @@
%%% @doc: Elli example callback
%%%
%%% Your callback needs to implement two functions, {@link handle/2} and
%%% {@link handle_event/3}. For every request, Elli will call your handle
%%% function with the request. When an event happens, like Elli
%%% completed a request, there was a parsing error or your handler
%%% threw an error, {@link handle_event/3} is called.
-module(wsEgHer).
-export([handle/2, handle_event/3]).
-export([chunk_loop/1]).
-include("wsCom.hrl").
-behaviour(wsHer).
-include("wsCom.hrl").
-include_lib("kernel/include/file.hrl").
%%
%% ELLI REQUEST CALLBACK
%%
%% @doc Handle a `Req'uest.
%% Delegate to our handler function.
%% @see handle/3
-spec handle(Req, _Args) -> Result when
Req :: elli:wsReq(),
_Args :: wsHer:callback_args(),
Result :: wsHer:result().
handle(Req, _Args) -> handle(Req#wsReq.method, wsReq:path(Req), Req).
-export([
handle/3
]).
-export([
chunk_loop/1
]).
%% @doc Route `Method' and `Path' to the appropriate clause.
%%
@ -49,33 +33,19 @@ handle(Req, _Args) -> handle(Req#wsReq.method, wsReq:path(Req), Req).
%% allows you to return an empty body. Useful for
%% implementing the `"304 Not Modified"' response.
%%
%% @see elli_request:get_arg/3
%% @see elli_request:post_arg/3
%% @see elli_request:post_arg_decoded/3
%% @see elli_request:get_header/3
%% @see elli_request:get_arg_decoded/3
%% @see elli_request:get_args_decoded/1
%% @see elli_util:file_size/1
%% @see elli_request:get_range/1
%% @see elli_request:normalize_range/2
%% @see elli_request:encode_range/2
%% @see elli_request:chunk_ref/1
%% @see chunk_loop/1
-spec handle(Method, Path, Req) -> wsHer:result() when
Method :: elli:method(),
Path :: [binary()],
Req :: elli:wsReq().
handle('GET', [<<"hello">>, <<"world">>], _Req) ->
-spec handle(Method :: method(), Path :: path(), Req :: wsReq()) -> wsHer:response().
handle('GET', <<"hello/world">>, wsReq) ->
%% Reply with a normal response.
timer:sleep(1000),
{ok, [], <<"Hello World!">>};
handle('GET', [<<"hello">>], Req) ->
handle('GET', <<"hello">>, Req) ->
%% Fetch a GET argument from the URL.
Name = wsReq:get_arg(<<"name">>, Req, <<"undefined">>),
{ok, [], <<"Hello ", Name/binary>>};
handle('POST', [<<"hello">>], Req) ->
handle('POST', <<"hello">>, Req) ->
%% Fetch a POST argument from the POST body.
Name = wsReq:post_arg(<<"name">>, Req, <<"undefined">>),
%% Fetch and decode
@ -225,102 +195,4 @@ chunk_loop(Ref, N) ->
ok -> ok;
{error, Reason} -> ?wsErr("error in sending chunk: ~p~n", [Reason])
end,
chunk_loop(Ref, N - 1).
%%
%% ELLI EVENT CALLBACKS
%%
%% @doc Handle Elli events, fired throughout processing a request.
%%
%% `elli_startup' is sent when Elli is starting up. If you are
%% implementing a middleware, you can use it to spawn processes,
%% create ETS tables or start supervised processes in a supervisor
%% tree.
%%
%% `request_complete' fires *after* Elli has sent the response to the
%% client. `Timings' contains timestamps (native units) of events like when the
%% connection was accepted, when headers/body parsing finished, when the
%% user callback returns, response sent, etc. `Sizes' contains response sizes
%% like response headers size, response body or file size.
%% This allows you to collect performance statistics for monitoring your app.
%%
%% `request_throw', `request_error' and `request_exit' events are sent if
%% the user callback code throws an exception, has an error or
%% exits. After triggering this event, a generated response is sent to
%% the user.
%%
%% `invalid_return' is sent if the user callback code returns a term not
%% understood by elli, see {@link elli_http:execute_callback/1}.
%% After triggering this event, a generated response is sent to the user.
%%
%% `chunk_complete' fires when a chunked response is completely
%% sent. It's identical to the `request_complete' event, except instead
%% of the response body you get the atom `client' or `server'
%% depending on who closed the connection. `Sizes' will have the key `chunks',
%% which is the total size of all chunks plus encoding overhead.
%%
%% `request_closed' is sent if the client closes the connection when
%% Elli is waiting for the next request on a keep alive connection.
%%
%% `request_timeout' is sent if the client times out when
%% Elli is waiting for the request.
%%
%% `request_parse_error' fires if the request is invalid and cannot be parsed by
%% [`erlang:decode_packet/3`][decode_packet/3] or it contains a path Elli cannot
%% parse or does not support.
%%
%% [decode_packet/3]: http://erlang.org/doc/man/erlang.html#decode_packet-3
%%
%% `client_closed' can be sent from multiple parts of the request
%% handling. It's sent when the client closes the connection or if for
%% any reason the socket is closed unexpectedly. The `Where' atom
%% tells you in which part of the request processing the closed socket
%% was detected: `receiving_headers', `receiving_body' or `before_response'.
%%
%% `client_timeout' can as with `client_closed' be sent from multiple
%% parts of the request handling. If Elli tries to receive data from
%% the client socket and does not receive anything within a timeout,
%% this event fires and the socket is closed.
%%
%% `bad_request' is sent when Elli detects a request is not well
%% formatted or does not conform to the configured limits. Currently
%% the `Reason' variable can be `{too_many_headers, Headers}'
%% or `{body_size, ContentLength}'.
%%
%% `file_error' is sent when the user wants to return a file as a
%% response, but for some reason it cannot be opened.
-spec handle_event(Event, Args, Config) -> ok when
Event :: elli:event(),
Args :: wsHer:callback_args(),
Config :: [tuple()].
handle_event(elli_startup, [], _) -> ok;
handle_event(request_complete, [_Request,
_ResponseCode, _ResponseHeaders, _ResponseBody,
{_Timings, _Sizes}], _) -> ok;
handle_event(request_throw, [_Request, _Exception, _Stacktrace], _) -> ok;
handle_event(request_error, [_Request, _Exception, _Stacktrace], _) -> ok;
handle_event(request_exit, [_Request, _Exception, _Stacktrace], _) -> ok;
handle_event(invalid_return, [_Request, _ReturnValue], _) -> ok;
handle_event(chunk_complete, [_Request,
_ResponseCode, _ResponseHeaders, _ClosingEnd,
{_Timings, _Sizes}], _) -> ok;
handle_event(request_closed, [], _) -> ok;
handle_event(request_timeout, [], _) -> ok;
handle_event(request_parse_error, [_], _) -> ok;
handle_event(client_closed, [_Where], _) -> ok;
handle_event(client_timeout, [_Where], _) -> ok;
handle_event(bad_request, [_Reason], _) -> ok;
handle_event(file_error, [_ErrorReason], _) -> ok.
chunk_loop(Ref, N - 1).

+ 0
- 26
src/example/wsEgMiddleware.erl View File

@ -1,26 +0,0 @@
%% @hidden
-module(wsEgMiddleware).
-export([handle/2, handle_event/3]).
-behaviour(wsHer).
%%
%% ELLI
%%
handle(Req, _Args) ->
do_handle(wsReq:path(Req)).
do_handle([<<"middleware">>, <<"short-circuit">>]) ->
{200, [], <<"short circuit!">>};
do_handle(_) ->
ignore.
%%
%% ELLI EVENT CALLBACKS
%%
handle_event(_Event, _Data, _Args) ->
ok.

+ 9
- 31
src/wsSrv/wsHer.erl View File

@ -2,38 +2,16 @@
-include("eWSrv.hrl").
-export_type([callback/0, callback_mod/0, callback_args/0, result/0]).
%% @type callback(). A tuple of a {@type callback_mod()} and {@type
%% callback_args()}.
-type callback() :: {callback_mod(), callback_args()}.
%% @type callback_mod(). A callback module.
-type callback_mod() :: module().
%% @type callback_args(). Arguments to pass to a {@type callback_mod()}.
-type callback_args() :: list().
-export_type([
response/0
]).
-type result() ::
{response_code() |ok, headers(), {file, file:name_all()}|
-type response() ::
{httpCode() | ok, body()}|
{httpCode() | ok, headers(), body()}|
{httpCode() | ok, headers(), {file, file:name_all()}|
{file, file:name_all(), wsUtil:range()}}|
{response_code() | ok, headers(), body()}|
{response_code() | ok, body()}|
{chunk, headers()}|
{chunk, headers(), body()}|
ignore.
-callback init(Req :: wsReq(), Args :: callback_args()) -> {ok, standard | handover}.
{chunk, headers(), body()}.
-callback handle(Req :: wsReq(), callback_args()) -> result().
-callback preprocess(Req1 :: wsReq(), Args :: callback_args()) -> Req2 :: wsReq().
-callback postprocess(Req :: wsReq(), Res1 :: result(), Args :: callback_args()) -> Res2 :: result().
-optional_callbacks([
init/2
, preprocess/2
, postprocess/3
]).
-callback handle(Method :: method(), Path :: binary(), Req :: wsReq()) -> response().

+ 1
- 1
src/wsSrv/wsHttp.erl View File

@ -239,7 +239,7 @@ sendResponse(Socket, Method, Code, Headers, UserBody) ->
%% and headers.
-spec send_file(Req, Code, Headers, Filename, Range) -> ok when
Req :: elli:wsReq(),
Code :: elli:response_code(),
Code :: elli:httpCode(),
Headers :: elli:headers(),
Filename :: file:filename(),
Range :: wsUtil:range().

+ 0
- 151
src/wsSrv/wsMiddleware.erl View File

@ -1,151 +0,0 @@
%%% @doc HTTP request processing middleware.
%%%
%%% This module offers both pre-processing of requests and post-processing of
%%% responses. It can also be used to allow multiple handlers, where the first
%%% handler to return a response short-circuits the request.
%%% It is implemented as a plain elli handler.
%%%
%%% Usage:
%%%
%%% ```
%%% Config = [
%%% {mods, [
%%% {elli_example_middleware, []},
%%% {elli_middleware_compress, []},
%%% {elli_example_callback, []}
%%% ]}
%%% ],
%%% elli:start_link([
%%% %% ...,
%%% {callback, elli_middleware},
%%% {callback_args, Config}
%%% ]).
%%% '''
%%%
%%% The configured modules may implement the elli behaviour, in which case all
%%% the callbacks will be used as normal. If {@link handle/2} returns `ignore',
%%% elli will continue on to the next callback in the list.
%%%
%%% Pre-processing and post-processing is implemented in {@link preprocess/2}
%%% and {@link postprocess/3}. {@link preprocess/2} is called for each
%%% middleware in the order specified, while {@link postprocess/3} is called in
%%% the reverse order.
%%%
%%% TODO: Don't call all postprocess middlewares when a middleware
%%% short-circuits the request.
%%%
%%% `elli_middleware' does not add any significant overhead.
-module(wsMiddleware).
-behaviour(wsHer).
-export([init/2, handle/2, handle_event/3]).
%% Macros.
-define(IF_NOT_EXPORTED(M, F, A, T, E),
case erlang:function_exported(M, F, A) of true -> E; false -> T end).
%%
%% ELLI CALLBACKS
%%
%% @hidden
-spec init(Req, Args) -> {ok, standard | handover} when
Req :: elli:wsReq(),
Args :: wsHer:callback_args().
init(Req, Args) ->
do_init(Req, callbacks(Args)).
%% @hidden
-spec handle(Req :: elli:wsReq(), Config :: [tuple()]) -> wsHer:result().
handle(CleanReq, Config) ->
Callbacks = callbacks(Config),
PreReq = preprocess(CleanReq, Callbacks),
Res = process(PreReq, Callbacks),
postprocess(PreReq, Res, lists:reverse(Callbacks)).
%% @hidden
-spec handle_event(Event, Args, Config) -> ok when
Event :: wsHer:event(),
Args :: wsHer:callback_args(),
Config :: [tuple()].
handle_event(elli_startup, Args, Config) ->
Callbacks = callbacks(Config),
[code:ensure_loaded(M) || {M, _} <- Callbacks],
forward_event(elli_startup, Args, Callbacks);
handle_event(Event, Args, Config) ->
forward_event(Event, Args, lists:reverse(callbacks(Config))).
%%
%% MIDDLEWARE LOGIC
%%
-spec do_init(Req, Callbacks) -> {ok, standard | handover} when
Req :: elli:wsReq(),
Callbacks :: wsHer:callbacks().
do_init(_, []) ->
{ok, standard};
do_init(Req, [{Mod, Args} | Mods]) ->
?IF_NOT_EXPORTED(Mod, init, 2, do_init(Req, Mods),
case Mod:init(Req, Args) of
ignore -> do_init(Req, Mods);
Result -> Result
end).
-spec process(Req, Callbacks) -> Result when
Req :: elli:wsReq(),
Callbacks :: [Callback :: wsHer:callback()],
Result :: wsHer:result().
process(_Req, []) ->
{404, [], <<"Not Found">>};
process(Req, [{Mod, Args} | Mods]) ->
?IF_NOT_EXPORTED(Mod, handle, 2, process(Req, Mods),
case Mod:handle(Req, Args) of
ignore -> process(Req, Mods);
Response -> Response
end).
-spec preprocess(Req1, Callbacks) -> Req2 when
Req1 :: elli:wsReq(),
Callbacks :: [wsHer:callback()],
Req2 :: elli:wsReq().
preprocess(Req, []) ->
Req;
preprocess(Req, [{Mod, Args} | Mods]) ->
?IF_NOT_EXPORTED(Mod, preprocess, 2, preprocess(Req, Mods),
preprocess(Mod:preprocess(Req, Args), Mods)).
-spec postprocess(Req, Res1, Callbacks) -> Res2 when
Req :: elli:wsReq(),
Res1 :: wsHer:result(),
Callbacks :: [wsHer:callback()],
Res2 :: wsHer:result().
postprocess(_Req, Res, []) ->
Res;
postprocess(Req, Res, [{Mod, Args} | Mods]) ->
?IF_NOT_EXPORTED(Mod, postprocess, 3, postprocess(Req, Res, Mods),
postprocess(Req, Mod:postprocess(Req, Res, Args), Mods)).
-spec forward_event(Event, Args, Callbacks) -> ok when
Event :: wsHer:event(),
Args :: wsHer:callback_args(),
Callbacks :: [wsHer:callback()].
forward_event(Event, Args, Callbacks) ->
[?IF_NOT_EXPORTED(M, handle_event, 3, ok,
M:handle_event(Event, Args, XArgs))
|| {M, XArgs} <- Callbacks],
ok.
%%
%% INTERNAL HELPERS
%%
-spec callbacks(Config :: [{mod, Callbacks} | tuple()]) -> Callbacks when
Callbacks :: [wsHer:callback()].
callbacks(Config) ->
proplists:get_value(mods, Config, []).

+ 0
- 57
src/wsSrv/wsMiddlewareCompress.erl View File

@ -1,57 +0,0 @@
%%% @doc Response compression as Elli middleware.
-module(wsMiddlewareCompress).
-export([postprocess/3]).
-include("wsCom.hrl").
%%
%% Postprocess handler
%%
%%% @doc Postprocess all requests and compress bodies larger than
%%% `compress_byte_size' (`1024' by default).
-spec postprocess(Req, Result, Config) -> Result when
Req :: elli:wsReq(),
Result :: wsHer:result(),
Config :: [{compress_byte_size, non_neg_integer()} | tuple()].
postprocess(Req, {ResponseCode, Body}, Config)
when is_integer(ResponseCode) orelse ResponseCode =:= ok ->
postprocess(Req, {ResponseCode, [], Body}, Config);
postprocess(Req, {ResponseCode, Headers, Body} = Res, Config)
when is_integer(ResponseCode) orelse ResponseCode =:= ok ->
Threshold = proplists:get_value(compress_byte_size, Config, 1024),
?IIF(not should_compress(Body, Threshold), Res,
case compress(Body, Req) of
no_compress ->
Res;
{CompressedBody, Encoding} ->
NewHeaders = [{<<"Content-Encoding">>, Encoding} | Headers],
{ResponseCode, NewHeaders, CompressedBody}
end);
postprocess(_, Res, _) ->
Res.
%%
%% INTERNALS
%%
%% NOTE: Algorithm is either `<<"gzip">>' or `<<"deflate">>'.
-spec compress(Body0 :: elli:body(), Req :: elli:wsReq()) -> Body1 when
Body1 :: {Compressed :: binary(), Algorithm :: binary()} | no_compress.
compress(Body, Req) ->
case accepted_encoding(Req) of
<<"gzip">> = E -> {zlib:gzip(Body), E};
<<"deflate">> = E -> {zlib:compress(Body), E};
_ -> no_compress
end.
accepted_encoding(Req) ->
hd(binary:split(wsReq:get_header(<<"Accept-Encoding">>, Req, <<>>),
[<<",">>, <<";">>], [global])).
-spec should_compress(Body, Threshold) -> boolean() when
Body :: binary(),
Threshold :: non_neg_integer().
should_compress(Body, S) ->
is_binary(Body) andalso byte_size(Body) >= S orelse
is_list(Body) andalso iolist_size(Body) >= S.

+ 1
- 70
src/wsSrv/wsNet.erl View File

@ -3,82 +3,13 @@
-module(wsNet).
-export([
listen/3
, accept/3
, recv/3
, send/2
send/2
, close/1
, setopts/2
, sendfile/5
, peername/1
]).
-export_type([socket/0]).
-type socket() :: {plain, inet:socket()} | {ssl, ssl:sslsocket()}.
listen(plain, Port, Opts) ->
case gen_tcp:listen(Port, Opts) of
{ok, Socket} ->
{ok, {plain, Socket}};
{error, Reason} ->
{error, Reason}
end;
listen(ssl, Port, Opts) ->
case ssl:listen(Port, Opts) of
{ok, Socket} ->
{ok, {ssl, Socket}};
{error, Reason} ->
{error, Reason}
end.
accept({plain, Socket}, Server, Timeout) ->
case gen_tcp:accept(Socket, Timeout) of
{ok, S} ->
gen_server:cast(Server, accepted),
{ok, {plain, S}};
{error, Reason} ->
{error, Reason}
end;
accept({ssl, Socket}, Server, Timeout) ->
case ssl:transport_accept(Socket, Timeout) of
{ok, S} ->
handshake(S, Server, Timeout);
{error, Reason} ->
{error, Reason}
end.
-ifdef(post20).
handshake(S, Server, Timeout) ->
case ssl:handshake(S, Timeout) of
{ok, S1} ->
gen_server:cast(Server, accepted),
{ok, {ssl, S1}};
{error, closed} ->
{error, econnaborted};
{error, Reason} ->
{error, Reason}
end.
-else.
handshake(S, Server, Timeout) ->
case ssl:ssl_accept(S, Timeout) of
ok ->
gen_server:cast(Server, accepted),
{ok, {ssl, S}};
{error, closed} ->
{error, econnaborted};
{error, Reason} ->
{error, Reason}
end.
-endif.
recv({plain, Socket}, Size, Timeout) ->
gen_tcp:recv(Socket, Size, Timeout);
recv({ssl, Socket}, Size, Timeout) ->
ssl:recv(Socket, Size, Timeout).
send({plain, Socket}, Data) ->
gen_tcp:send(Socket, Data);
send({ssl, Socket}, Data) ->

+ 0
- 27
src/wsSrv/wsReq.erl View File

@ -7,8 +7,6 @@
, async_send_chunk/2
, chunk_ref/1
, close_chunk/1
, path/1
, raw_path/1
, query_str/1
, get_header/2
, get_header/3
@ -25,12 +23,6 @@
, post_args/1
, post_args_decoded/1
, body_qs/1
, headers/1
, method/1
, body/1
, scheme/1
, host/1
, port/1
, get_range/1
, to_proplist/1
, is_request/1
@ -48,25 +40,6 @@
%% Helpers for working with a #req{}
%%
%% @doc Return `path' split into binary parts.
path(#wsReq{path = Path}) -> Path.
%% @doc Return the `raw_path', i.e. not split or parsed for query params.
raw_path(#wsReq{path = Path}) -> Path.
%% @doc Return the `headers' that have had `string:casefold/1' run on each key.
headers(#wsReq{headers = Headers}) -> Headers.
%% @doc Return the original `headers'.
%% @doc Return the `method'.
method(#wsReq{method = Method}) -> Method.
%% @doc Return the `body'.
body(#wsReq{body = Body}) -> Body.
%% @doc Return the `scheme'.
scheme(#wsReq{scheme = Scheme}) -> Scheme.
%% @doc Return the `host'.
host(#wsReq{host = Host}) -> Host.
%% @doc Return the `port'.
port(#wsReq{port = Port}) -> Port.
get_header(Key, #wsReq{headers = Headers}) ->
CaseFoldedKey = string:casefold(Key),
proplists:get_value(CaseFoldedKey, Headers).

+ 1
- 1
src/wsSrv/wsSendFile.erl View File

@ -1,6 +1,6 @@
-module(wsSendFile).
-include("eWSrv.hrl").
-include("wsCom.hrl").
-export([
sendfile/5

Loading…
Cancel
Save