Browse Source

Improve the specs for cowboy_req:init_stream/4

Loïc Hoguin 12 years ago
parent
commit
ba7e6c07ec
1 changed files with 14 additions and 4 deletions
  1. 14 4
      src/cowboy_req.erl

+ 14 - 4
src/cowboy_req.erl

@@ -120,6 +120,16 @@
 -type cookie_opts() :: [cookie_option()].
 -type cookie_opts() :: [cookie_option()].
 -export_type([cookie_opts/0]).
 -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 resp_body_fun() :: fun((inet:socket(), module()) -> ok).
 -type send_chunk_fun() :: fun((iodata()) -> ok | {error, atom()}).
 -type send_chunk_fun() :: fun((iodata()) -> ok | {error, atom()}).
 -type resp_chunked_fun() :: fun((send_chunk_fun()) -> ok).
 -type resp_chunked_fun() :: fun((send_chunk_fun()) -> ok).
@@ -149,8 +159,8 @@
 	meta = [] :: [{atom(), any()}],
 	meta = [] :: [{atom(), any()}],
 
 
 	%% Request body.
 	%% 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()},
 	multipart = undefined :: undefined | {non_neg_integer(), fun()},
 	buffer = <<>> :: binary(),
 	buffer = <<>> :: binary(),
 
 
@@ -572,7 +582,7 @@ body_length(Req) ->
 %% Content encoding is generally used for compression.
 %% Content encoding is generally used for compression.
 %%
 %%
 %% Standard encodings can be found in cowboy_http.
 %% 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().
 	-> {ok, Req} when Req::req().
 init_stream(TransferDecode, TransferState, ContentDecode, Req) ->
 init_stream(TransferDecode, TransferState, ContentDecode, Req) ->
 	{ok, Req#http_req{body_state=
 	{ok, Req#http_req{body_state=
@@ -691,7 +701,7 @@ transfer_decode_done(Length, Rest, Req=#http_req{
 		headers=Headers3, p_headers=PHeaders3}.
 		headers=Headers3, p_headers=PHeaders3}.
 
 
 %% @todo Probably needs a Rest.
 %% @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().
 	-> {ok, binary(), Req} | {error, atom()} when Req::req().
 content_decode(ContentDecode, Data, Req) ->
 content_decode(ContentDecode, Data, Req) ->
 	case ContentDecode(Data) of
 	case ContentDecode(Data) of