mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Move cowboy_http:status() to cowboy:http_status()
This commit is contained in:
parent
f8a7856127
commit
df73a4d0a5
7 changed files with 19 additions and 20 deletions
|
@ -23,6 +23,9 @@
|
||||||
-type http_headers() :: [{binary(), iodata()}].
|
-type http_headers() :: [{binary(), iodata()}].
|
||||||
-export_type([http_headers/0]).
|
-export_type([http_headers/0]).
|
||||||
|
|
||||||
|
-type http_status() :: non_neg_integer() | binary().
|
||||||
|
-export_type([http_status/0]).
|
||||||
|
|
||||||
-type http_version() :: 'HTTP/1.1' | 'HTTP/1.0'.
|
-type http_version() :: 'HTTP/1.1' | 'HTTP/1.0'.
|
||||||
-export_type([http_version/0]).
|
-export_type([http_version/0]).
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ handler_init(Req, State, Handler, HandlerOpts) ->
|
||||||
-> {ok, Req, Env}
|
-> {ok, Req, Env}
|
||||||
| {suspend, module(), atom(), any()}
|
| {suspend, module(), atom(), any()}
|
||||||
| {halt, Req}
|
| {halt, Req}
|
||||||
| {error, cowboy_http:status(), Req}
|
| {error, cowboy:http_status(), Req}
|
||||||
when Req::cowboy_req:req(), Env::cowboy_middleware:env().
|
when Req::cowboy_req:req(), Env::cowboy_middleware:env().
|
||||||
upgrade_protocol(Req, #state{env=Env},
|
upgrade_protocol(Req, #state{env=Env},
|
||||||
Handler, HandlerOpts, Module) ->
|
Handler, HandlerOpts, Module) ->
|
||||||
|
|
|
@ -52,10 +52,6 @@
|
||||||
-export([urlencode/2]).
|
-export([urlencode/2]).
|
||||||
-export([x_www_form_urlencoded/1]).
|
-export([x_www_form_urlencoded/1]).
|
||||||
|
|
||||||
-type status() :: non_neg_integer() | binary().
|
|
||||||
|
|
||||||
-export_type([status/0]).
|
|
||||||
|
|
||||||
%% Parsing.
|
%% Parsing.
|
||||||
|
|
||||||
%% @doc Parse a non-empty list of the given type.
|
%% @doc Parse a non-empty list of the given type.
|
||||||
|
|
|
@ -32,5 +32,5 @@
|
||||||
-> {ok, Req, Env}
|
-> {ok, Req, Env}
|
||||||
| {suspend, module(), atom(), [any()]}
|
| {suspend, module(), atom(), [any()]}
|
||||||
| {halt, Req}
|
| {halt, Req}
|
||||||
| {error, cowboy_http:status(), Req}
|
| {error, cowboy:http_status(), Req}
|
||||||
when Req::cowboy_req:req(), Env::env().
|
when Req::cowboy_req:req(), Env::env().
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
|
|
||||||
-type onrequest_fun() :: fun((Req) -> Req).
|
-type onrequest_fun() :: fun((Req) -> Req).
|
||||||
-type onresponse_fun() ::
|
-type onresponse_fun() ::
|
||||||
fun((cowboy_http:status(), cowboy:http_headers(), iodata(), Req) -> Req).
|
fun((cowboy:http_status(), cowboy:http_headers(), iodata(), Req) -> Req).
|
||||||
-export_type([onrequest_fun/0]).
|
-export_type([onrequest_fun/0]).
|
||||||
-export_type([onresponse_fun/0]).
|
-export_type([onresponse_fun/0]).
|
||||||
|
|
||||||
|
@ -565,7 +565,7 @@ next_request(Req, State=#state{req_keepalive=Keepalive, timeout=Timeout},
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% Only send an error reply if there is no resp_sent message.
|
%% Only send an error reply if there is no resp_sent message.
|
||||||
-spec error_terminate(cowboy_http:status(), cowboy_req:req(), #state{}) -> ok.
|
-spec error_terminate(cowboy:http_status(), cowboy_req:req(), #state{}) -> ok.
|
||||||
error_terminate(Code, Req, State) ->
|
error_terminate(Code, Req, State) ->
|
||||||
receive
|
receive
|
||||||
{cowboy_req, resp_sent} -> ok
|
{cowboy_req, resp_sent} -> ok
|
||||||
|
@ -576,7 +576,7 @@ error_terminate(Code, Req, State) ->
|
||||||
terminate(State).
|
terminate(State).
|
||||||
|
|
||||||
%% Only send an error reply if there is no resp_sent message.
|
%% Only send an error reply if there is no resp_sent message.
|
||||||
-spec error_terminate(cowboy_http:status(), #state{}) -> ok.
|
-spec error_terminate(cowboy:http_status(), #state{}) -> ok.
|
||||||
error_terminate(Code, State=#state{socket=Socket, transport=Transport,
|
error_terminate(Code, State=#state{socket=Socket, transport=Transport,
|
||||||
compress=Compress, onresponse=OnResponse}) ->
|
compress=Compress, onresponse=OnResponse}) ->
|
||||||
receive
|
receive
|
||||||
|
|
|
@ -925,18 +925,18 @@ delete_resp_header(Name, Req=#http_req{resp_headers=RespHeaders}) ->
|
||||||
Req#http_req{resp_headers=RespHeaders2}.
|
Req#http_req{resp_headers=RespHeaders2}.
|
||||||
|
|
||||||
%% @equiv reply(Status, [], [], Req)
|
%% @equiv reply(Status, [], [], Req)
|
||||||
-spec reply(cowboy_http:status(), Req) -> {ok, Req} when Req::req().
|
-spec reply(cowboy:http_status(), Req) -> {ok, Req} when Req::req().
|
||||||
reply(Status, Req=#http_req{resp_body=Body}) ->
|
reply(Status, Req=#http_req{resp_body=Body}) ->
|
||||||
reply(Status, [], Body, Req).
|
reply(Status, [], Body, Req).
|
||||||
|
|
||||||
%% @equiv reply(Status, Headers, [], Req)
|
%% @equiv reply(Status, Headers, [], Req)
|
||||||
-spec reply(cowboy_http:status(), cowboy:http_headers(), Req)
|
-spec reply(cowboy:http_status(), cowboy:http_headers(), Req)
|
||||||
-> {ok, Req} when Req::req().
|
-> {ok, Req} when Req::req().
|
||||||
reply(Status, Headers, Req=#http_req{resp_body=Body}) ->
|
reply(Status, Headers, Req=#http_req{resp_body=Body}) ->
|
||||||
reply(Status, Headers, Body, Req).
|
reply(Status, Headers, Body, Req).
|
||||||
|
|
||||||
%% @doc Send a reply to the client.
|
%% @doc Send a reply to the client.
|
||||||
-spec reply(cowboy_http:status(), cowboy:http_headers(),
|
-spec reply(cowboy:http_status(), cowboy:http_headers(),
|
||||||
iodata() | {non_neg_integer() | resp_body_fun()}, Req)
|
iodata() | {non_neg_integer() | resp_body_fun()}, Req)
|
||||||
-> {ok, Req} when Req::req().
|
-> {ok, Req} when Req::req().
|
||||||
reply(Status, Headers, Body, Req=#http_req{
|
reply(Status, Headers, Body, Req=#http_req{
|
||||||
|
@ -1047,13 +1047,13 @@ reply_no_compress(Status, Headers, Body, Req,
|
||||||
Req2.
|
Req2.
|
||||||
|
|
||||||
%% @equiv chunked_reply(Status, [], Req)
|
%% @equiv chunked_reply(Status, [], Req)
|
||||||
-spec chunked_reply(cowboy_http:status(), Req) -> {ok, Req} when Req::req().
|
-spec chunked_reply(cowboy:http_status(), Req) -> {ok, Req} when Req::req().
|
||||||
chunked_reply(Status, Req) ->
|
chunked_reply(Status, Req) ->
|
||||||
chunked_reply(Status, [], Req).
|
chunked_reply(Status, [], Req).
|
||||||
|
|
||||||
%% @doc Initiate the sending of a chunked reply to the client.
|
%% @doc Initiate the sending of a chunked reply to the client.
|
||||||
%% @see cowboy_req:chunk/2
|
%% @see cowboy_req:chunk/2
|
||||||
-spec chunked_reply(cowboy_http:status(), cowboy:http_headers(), Req)
|
-spec chunked_reply(cowboy:http_status(), cowboy:http_headers(), Req)
|
||||||
-> {ok, Req} when Req::req().
|
-> {ok, Req} when Req::req().
|
||||||
chunked_reply(Status, Headers, Req) ->
|
chunked_reply(Status, Headers, Req) ->
|
||||||
{_, Req2} = chunked_response(Status, Headers, Req),
|
{_, Req2} = chunked_response(Status, Headers, Req),
|
||||||
|
@ -1073,7 +1073,7 @@ chunk(Data, #http_req{socket=Socket, transport=Transport, resp_state=chunks}) ->
|
||||||
|
|
||||||
%% @doc Send an upgrade reply.
|
%% @doc Send an upgrade reply.
|
||||||
%% @private
|
%% @private
|
||||||
-spec upgrade_reply(cowboy_http:status(), cowboy:http_headers(), Req)
|
-spec upgrade_reply(cowboy:http_status(), cowboy:http_headers(), Req)
|
||||||
-> {ok, Req} when Req::req().
|
-> {ok, Req} when Req::req().
|
||||||
upgrade_reply(Status, Headers, Req=#http_req{
|
upgrade_reply(Status, Headers, Req=#http_req{
|
||||||
resp_state=waiting, resp_headers=RespHeaders}) ->
|
resp_state=waiting, resp_headers=RespHeaders}) ->
|
||||||
|
@ -1084,7 +1084,7 @@ upgrade_reply(Status, Headers, Req=#http_req{
|
||||||
|
|
||||||
%% @doc Ensure the response has been sent fully.
|
%% @doc Ensure the response has been sent fully.
|
||||||
%% @private
|
%% @private
|
||||||
-spec ensure_response(req(), cowboy_http:status()) -> ok.
|
-spec ensure_response(req(), cowboy:http_status()) -> ok.
|
||||||
%% The response has already been fully sent to the client.
|
%% The response has already been fully sent to the client.
|
||||||
ensure_response(#http_req{resp_state=done}, _) ->
|
ensure_response(#http_req{resp_state=done}, _) ->
|
||||||
ok;
|
ok;
|
||||||
|
@ -1210,7 +1210,7 @@ to_list(Req) ->
|
||||||
|
|
||||||
%% Internal.
|
%% Internal.
|
||||||
|
|
||||||
-spec chunked_response(cowboy_http:status(), cowboy:http_headers(), Req) ->
|
-spec chunked_response(cowboy:http_status(), cowboy:http_headers(), Req) ->
|
||||||
{normal | hook, Req} when Req::req().
|
{normal | hook, Req} when Req::req().
|
||||||
chunked_response(Status, Headers, Req=#http_req{
|
chunked_response(Status, Headers, Req=#http_req{
|
||||||
version=Version, connection=Connection,
|
version=Version, connection=Connection,
|
||||||
|
@ -1229,7 +1229,7 @@ chunked_response(Status, Headers, Req=#http_req{
|
||||||
{RespType, Req2#http_req{connection=RespConn, resp_state=chunks,
|
{RespType, Req2#http_req{connection=RespConn, resp_state=chunks,
|
||||||
resp_headers=[], resp_body= <<>>}}.
|
resp_headers=[], resp_body= <<>>}}.
|
||||||
|
|
||||||
-spec response(cowboy_http:status(), cowboy:http_headers(),
|
-spec response(cowboy:http_status(), cowboy:http_headers(),
|
||||||
cowboy:http_headers(), cowboy:http_headers(), iodata(), Req)
|
cowboy:http_headers(), cowboy:http_headers(), iodata(), Req)
|
||||||
-> {normal | hook, Req} when Req::req().
|
-> {normal | hook, Req} when Req::req().
|
||||||
response(Status, Headers, RespHeaders, DefaultHeaders, Body, Req=#http_req{
|
response(Status, Headers, RespHeaders, DefaultHeaders, Body, Req=#http_req{
|
||||||
|
@ -1371,7 +1371,7 @@ connection_to_atom([<<"close">>|_]) ->
|
||||||
connection_to_atom([_|Tail]) ->
|
connection_to_atom([_|Tail]) ->
|
||||||
connection_to_atom(Tail).
|
connection_to_atom(Tail).
|
||||||
|
|
||||||
-spec status(cowboy_http:status()) -> binary().
|
-spec status(cowboy:http_status()) -> binary().
|
||||||
status(100) -> <<"100 Continue">>;
|
status(100) -> <<"100 Continue">>;
|
||||||
status(101) -> <<"101 Switching Protocols">>;
|
status(101) -> <<"101 Switching Protocols">>;
|
||||||
status(102) -> <<"102 Processing">>;
|
status(102) -> <<"102 Processing">>;
|
||||||
|
|
|
@ -33,5 +33,5 @@
|
||||||
-> {ok, Req, Env}
|
-> {ok, Req, Env}
|
||||||
| {suspend, module(), atom(), [any()]}
|
| {suspend, module(), atom(), [any()]}
|
||||||
| {halt, Req}
|
| {halt, Req}
|
||||||
| {error, cowboy_http:status(), Req}
|
| {error, cowboy:http_status(), Req}
|
||||||
when Req::cowboy_req:req(), Env::cowboy_middleware:env().
|
when Req::cowboy_req:req(), Env::cowboy_middleware:env().
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue