aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http_req.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-07-21 19:43:23 +0200
committerLoïc Hoguin <[email protected]>2012-07-22 05:09:42 +0200
commitdc759faf605ed1f3a0d2a82247a92a480755465a (patch)
tree760c6f3463e309438f5b1653b2d2ed6b7edc234a /src/cowboy_http_req.erl
parent3d1ddd1d8a69bd4a68b2fa555cc0146c7c1f04da (diff)
downloadcowboy-dc759faf605ed1f3a0d2a82247a92a480755465a.tar.gz
cowboy-dc759faf605ed1f3a0d2a82247a92a480755465a.tar.bz2
cowboy-dc759faf605ed1f3a0d2a82247a92a480755465a.zip
Add support for Expect: 100-continue
This makes uploading files with curl a lot faster than without.
Diffstat (limited to 'src/cowboy_http_req.erl')
-rw-r--r--src/cowboy_http_req.erl17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl
index 3227e15..70d627d 100644
--- a/src/cowboy_http_req.erl
+++ b/src/cowboy_http_req.erl
@@ -275,7 +275,7 @@ parse_header(Name, Req, Default) when Name =:= 'Content-Type' ->
fun (Value) ->
cowboy_http:content_type(Value)
end);
-parse_header(Name, Req, Default) when Name =:= 'Expect' ->
+parse_header(Name, Req, Default) when Name =:= <<"Expect">> ->
parse_header(Name, Req, Default,
fun (Value) ->
cowboy_http:nonempty_list(Value, fun cowboy_http:expectation/2)
@@ -429,8 +429,19 @@ init_stream(TransferDecode, TransferState, ContentDecode, Req) ->
%% for each streamed part, and {done, Req} when it's finished streaming.
-spec stream_body(#http_req{}) -> {ok, binary(), #http_req{}}
| {done, #http_req{}} | {error, atom()}.
-stream_body(Req=#http_req{body_state=waiting}) ->
- case parse_header('Transfer-Encoding', Req) of
+stream_body(Req=#http_req{body_state=waiting,
+ version=Version, transport=Transport, socket=Socket}) ->
+ case parse_header(<<"Expect">>, Req) of
+ {[<<"100-continue">>], Req1} ->
+ HTTPVer = cowboy_http:version_to_binary(Version),
+ Transport:send(Socket,
+ << HTTPVer/binary, " ", (status(100))/binary, "\r\n\r\n" >>);
+ {undefined, Req1} ->
+ ok;
+ {undefined, _, Req1} ->
+ ok
+ end,
+ case parse_header('Transfer-Encoding', Req1) of
{[<<"chunked">>], Req2} ->
stream_body(Req2#http_req{body_state=
{stream, fun cowboy_http:te_chunked/2, {0, 0},