You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
lettestfun()=let url ="https://httpbin.org/status/200"inlet headers = [ ("Test-header", "this should not appear in output"); ("Content-Type", "application/json") ] inlet body ="[\"post body\"]"inlet request =Cohttp_curl_lwt.Request.create
~headers:(Http.Header.of_list headers)
`POST~uri:url
~input:(Cohttp_curl_lwt.Source.string body)
~output:Cohttp_curl_lwt.Sink.stringinlet context =Cohttp_curl_lwt.Context.create ()inlet cohttp_response =Cohttp_curl_lwt.submit context request inlet response_body =Cohttp_curl_lwt.Response.body cohttp_response inletopenLwt.Syntaxinlet+ response_body = response_body in
print_endline response_body
let()=Lwt_main.run (testfun ())
The code here should just return the empty body that the URL usually gives, but instead it gives the first header. Similarly, https://httpbin.org/post is supposed to give you valid JSON, but here the header is prepended so it doesn't.
A glance at the code in cohttp_curl.ml shows that a Buffer called buf is created and shared between both the header formatting step and the output reading step:
Curl.setopt h (CURLOPT_READFUNCTION (Source.to_curl_callback input));
Curl.setopt h
(CURLOPT_WRITEFUNCTION
(match output with
|Discard -> funs -> String.length s
|String ->
response_body :=Some buf;
funs ->
Buffer.add_string buf s;
String.length s));
However the buffer is not cleared between these two steps, meaning whichever header it processed last is still in the buffer before it starts getting data from curl.
The text was updated successfully, but these errors were encountered:
Example:
The code here should just return the empty body that the URL usually gives, but instead it gives the first header. Similarly,
https://httpbin.org/post
is supposed to give you valid JSON, but here the header is prepended so it doesn't.A glance at the code in
cohttp_curl.ml
shows that a Buffer calledbuf
is created and shared between both the header formatting step and the output reading step:ocaml-cohttp/cohttp-curl/src/cohttp_curl.ml
Lines 56 to 126 in b7182a1
However the buffer is not cleared between these two steps, meaning whichever header it processed last is still in the buffer before it starts getting data from curl.
The text was updated successfully, but these errors were encountered: