mirror of
https://github.com/c-cube/ezcurl.git
synced 2025-12-06 03:05:31 -05:00
Merge pull request #13 from c-cube/fix-12
Fix #12: set size properly for POST
This commit is contained in:
commit
52c35dc2df
2 changed files with 14 additions and 5 deletions
3
Makefile
3
Makefile
|
|
@ -13,7 +13,8 @@ clean:
|
||||||
doc:
|
doc:
|
||||||
@dune build @doc
|
@dune build @doc
|
||||||
|
|
||||||
|
WATCH?=@all
|
||||||
watch:
|
watch:
|
||||||
@dune build @all -w
|
@dune build $(WATCH )-w
|
||||||
|
|
||||||
.PHONY: all build test watch
|
.PHONY: all build test watch
|
||||||
|
|
|
||||||
|
|
@ -311,15 +311,21 @@ module Make(IO : IO)
|
||||||
in
|
in
|
||||||
_apply_config self config;
|
_apply_config self config;
|
||||||
opt_iter range ~f:(fun s -> Curl.set_range self s);
|
opt_iter range ~f:(fun s -> Curl.set_range self s);
|
||||||
|
|
||||||
(* TODO: ability to make content a stream with a `read` function *)
|
(* TODO: ability to make content a stream with a `read` function *)
|
||||||
opt_iter content
|
opt_iter content
|
||||||
~f:(fun content ->
|
~f:(fun content ->
|
||||||
Curl.set_readfunction self (content_read_fun_ content);
|
Curl.set_readfunction self (content_read_fun_ content);
|
||||||
(* also set size if known *)
|
(* also set size if known *)
|
||||||
match content_size_ content with
|
match content_size_ content, meth with
|
||||||
| None -> headers := ("transfer-encoding", "chunked") :: !headers
|
| None, _ ->
|
||||||
| Some size -> Curl.set_infilesize self size
|
headers := ("expect", "") :: ("transfer-encoding", "chunked") :: !headers
|
||||||
|
| Some size , POST _ ->
|
||||||
|
Curl.set_postfieldsize self size;
|
||||||
|
| Some size, _ ->
|
||||||
|
Curl.set_infilesize self size
|
||||||
);
|
);
|
||||||
|
|
||||||
(* local state *)
|
(* local state *)
|
||||||
let tries = max tries 1 in (* at least one attempt *)
|
let tries = max tries 1 in (* at least one attempt *)
|
||||||
let body = Buffer.create 64 in
|
let body = Buffer.create 64 in
|
||||||
|
|
@ -329,7 +335,8 @@ module Make(IO : IO)
|
||||||
begin match meth with
|
begin match meth with
|
||||||
| POST [] when (content <> None) ->
|
| POST [] when (content <> None) ->
|
||||||
Curl.set_post self true
|
Curl.set_post self true
|
||||||
| POST l -> Curl.set_httppost self l;
|
| POST l ->
|
||||||
|
Curl.set_httppost self l;
|
||||||
| GET -> Curl.set_httpget self true;
|
| GET -> Curl.set_httpget self true;
|
||||||
| PUT ->
|
| PUT ->
|
||||||
Curl.set_customrequest self "PUT";
|
Curl.set_customrequest self "PUT";
|
||||||
|
|
@ -341,6 +348,7 @@ module Make(IO : IO)
|
||||||
| TRACE -> Curl.set_customrequest self "TRACE"
|
| TRACE -> Curl.set_customrequest self "TRACE"
|
||||||
| PATCH -> Curl.set_customrequest self "PATCH"
|
| PATCH -> Curl.set_customrequest self "PATCH"
|
||||||
end;
|
end;
|
||||||
|
|
||||||
_set_headers self !headers;
|
_set_headers self !headers;
|
||||||
Curl.set_headerfunction self
|
Curl.set_headerfunction self
|
||||||
(fun s0 ->
|
(fun s0 ->
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue