diff options
author | Filipe David Manana <[email protected]> | 2010-09-26 11:58:45 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2010-10-05 15:08:23 +0200 |
commit | f9ec3cbca0f05fd9640bbd5cd3e21942c4512d3d (patch) | |
tree | 0b71168e700abdd029136dbadb3b6b2c89b97d71 /lib/inets/src/http_client/httpc.erl | |
parent | 0a1f48c46cf629af7d3719e94250733d1589efa1 (diff) | |
download | otp-f9ec3cbca0f05fd9640bbd5cd3e21942c4512d3d.tar.gz otp-f9ec3cbca0f05fd9640bbd5cd3e21942c4512d3d.tar.bz2 otp-f9ec3cbca0f05fd9640bbd5cd3e21942c4512d3d.zip |
httpc: allow streaming of PUT and POST request bodies
This is a must when uploading large bodies that are to large to store
in a string or binary.
Besides a string or binary, a body can now be a function and
an accumulator.
Example:
-module(httpc_post_stream_test).
-compile(export_all).
-define(LEN, 1024 * 1024).
prepare_data() ->
{ok, Fd} = file:open("test_data.dat", [binary, write]),
ok = file:write(Fd, lists:duplicate(?LEN, "1")),
ok = file:close(Fd).
test() ->
inets:start(),
ok = prepare_data(),
{ok, Fd1} = file:open("test_data.dat", [binary, read]),
BodyFun = fun(Fd) ->
case file:read(Fd, 512) of
eof ->
eof;
{ok, Data} ->
{ok, Data, Fd}
end
end,
{ok, {{_,200,_}, _, _}} = httpc:request(post, {"http://localhost:8888",
[{"content-length", integer_to_list(?LEN)}], "text/plain", {BodyFun, Fd1}}, [], []),
ok = file:close(Fd1).
Diffstat (limited to 'lib/inets/src/http_client/httpc.erl')
-rw-r--r-- | lib/inets/src/http_client/httpc.erl | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/inets/src/http_client/httpc.erl b/lib/inets/src/http_client/httpc.erl index 851364001c..b82a9db4c9 100644 --- a/lib/inets/src/http_client/httpc.erl +++ b/lib/inets/src/http_client/httpc.erl @@ -126,7 +126,9 @@ request(Url, Profile) -> %% Header = {Field, Value} %% Field = string() %% Value = string() -%% Body = string() | binary() - HTLM-code +%% Body = string() | binary() | {fun(SendAcc) -> SendFunResult, SendAcc} - HTLM-code +%% SendFunResult = eof | {ok, iolist(), NewSendAcc} +%% SendAcc = NewSendAcc = term() %% %% Description: Sends a HTTP-request. The function can be both %% syncronus and asynchronous in the later case the function will |