似乎(基于wireshark),cohttp客户端在收到对GET请求的响应后自动关闭其连接。
有没有办法让这个连接保持活着(让它持久)?
如果没有任何其他HTTP库来创建持久连接?</ p>
答案 0 :(得分:2)
查看github处的代码,看起来没有这样的选项。
let call ?(ctx=default_ctx) ?headers ?(body=`Empty) ?chunked meth uri =
...
Net.connect_uri ~ctx uri >>= fun (conn, ic, oc) ->
let closefn () = Net.close ic oc in
...
read_response ~closefn ic oc meth
read_response
的位置:
let read_response ~closefn ic oc meth =
...
match has_body with
| `Yes | `Unknown ->
let reader = Response.make_body_reader res ic in
let stream = Body.create_stream Response.read_body_chunk reader in
let closefn = closefn in
Lwt_stream.on_terminate stream closefn;
let gcfn st = closefn () in
Gc.finalise gcfn stream;
let body = Body.of_stream stream in
return (res, body)
如果我正确读取此信息,一旦GC清理了流,连接就会关闭。