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/doc/src | |
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/doc/src')
-rw-r--r-- | lib/inets/doc/src/httpc.xml | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/inets/doc/src/httpc.xml b/lib/inets/doc/src/httpc.xml index 9c8df28fec..df333074cd 100644 --- a/lib/inets/doc/src/httpc.xml +++ b/lib/inets/doc/src/httpc.xml @@ -89,7 +89,9 @@ headers() = [header()] header() = {field(), value()} field() = string() value() = string() -body() = string() | binary() +body() = string() | binary() | {fun(acc()) -> send_fun_result(), acc()} +send_fun_result() = eof | {ok, iolist(), acc()} +acc() = term() filename() = string() ]]></code> |