aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-05-16 15:54:30 +0200
committerLoïc Hoguin <[email protected]>2013-05-16 15:54:30 +0200
commitba7e6c07ecfb24464bf83825dc4d749fd378c78b (patch)
tree2dfa7170a7cdeed75abd55796a616fd5e8258c5a
parent934393a16884729bee6b7a9418eee2262af9c216 (diff)
downloadcowboy-ba7e6c07ecfb24464bf83825dc4d749fd378c78b.tar.gz
cowboy-ba7e6c07ecfb24464bf83825dc4d749fd378c78b.tar.bz2
cowboy-ba7e6c07ecfb24464bf83825dc4d749fd378c78b.zip
Improve the specs for cowboy_req:init_stream/4
-rw-r--r--src/cowboy_req.erl18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index cbed01f..cc6063e 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -120,6 +120,16 @@
-type cookie_opts() :: [cookie_option()].
-export_type([cookie_opts/0]).
+-type content_decode_fun() :: fun((binary())
+ -> {ok, binary()}
+ | {error, atom()}).
+-type transfer_decode_fun() :: fun((binary(), any())
+ -> {ok, binary(), binary(), any()}
+ | more | {more, non_neg_integer(), binary(), any()}
+ | {done, non_neg_integer(), binary()}
+ | {done, binary(), non_neg_integer(), binary()}
+ | {error, atom()}).
+
-type resp_body_fun() :: fun((inet:socket(), module()) -> ok).
-type send_chunk_fun() :: fun((iodata()) -> ok | {error, atom()}).
-type resp_chunked_fun() :: fun((send_chunk_fun()) -> ok).
@@ -149,8 +159,8 @@
meta = [] :: [{atom(), any()}],
%% Request body.
- body_state = waiting :: waiting | done
- | {stream, non_neg_integer(), fun(), any(), fun()},
+ body_state = waiting :: waiting | done | {stream, non_neg_integer(),
+ transfer_decode_fun(), any(), content_decode_fun()},
multipart = undefined :: undefined | {non_neg_integer(), fun()},
buffer = <<>> :: binary(),
@@ -572,7 +582,7 @@ body_length(Req) ->
%% Content encoding is generally used for compression.
%%
%% Standard encodings can be found in cowboy_http.
--spec init_stream(fun(), any(), fun(), Req)
+-spec init_stream(transfer_decode_fun(), any(), content_decode_fun(), Req)
-> {ok, Req} when Req::req().
init_stream(TransferDecode, TransferState, ContentDecode, Req) ->
{ok, Req#http_req{body_state=
@@ -691,7 +701,7 @@ transfer_decode_done(Length, Rest, Req=#http_req{
headers=Headers3, p_headers=PHeaders3}.
%% @todo Probably needs a Rest.
--spec content_decode(fun(), binary(), Req)
+-spec content_decode(content_decode_fun(), binary(), Req)
-> {ok, binary(), Req} | {error, atom()} when Req::req().
content_decode(ContentDecode, Data, Req) ->
case ContentDecode(Data) of