From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id DA6C38018B for ; Thu, 6 Jul 2017 00:55:56 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=shayne.fletcher.50@gmail.com; spf=Pass smtp.mailfrom=shayne.fletcher.50@gmail.com; spf=None smtp.helo=postmaster@mail-vk0-f52.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of shayne.fletcher.50@gmail.com) identity=pra; client-ip=209.85.213.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="shayne.fletcher.50@gmail.com"; x-sender="shayne.fletcher.50@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of shayne.fletcher.50@gmail.com designates 209.85.213.52 as permitted sender) identity=mailfrom; client-ip=209.85.213.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="shayne.fletcher.50@gmail.com"; x-sender="shayne.fletcher.50@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-vk0-f52.google.com) identity=helo; client-ip=209.85.213.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="shayne.fletcher.50@gmail.com"; x-sender="postmaster@mail-vk0-f52.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AwUwqwxVbnv14IQcynLcRKuJTAJLV8LGtZVwlr6E/?= =?us-ascii?q?grcLSJyIuqrYbBCDt8tkgFKBZ4jH8fUM07OQ6PG/HzRYqb+681k6OKRWUBEEjc?= =?us-ascii?q?hE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRo?= =?us-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wA+9rOV7TKS7ni9IFVGMLpRYWTerwiVTEXyQFNFioWK?= =?us-ascii?q?dp3TEyGYSrRanHS5ymgLGblHOgHpRHYG0ABFSBDXzoep/CBq8kZyebI8snmTsB?= =?us-ascii?q?A+vyA7Q93A2j4Vepg4FsKfDZr3UV?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0DzCAD+bV1ZgDTVVdFcHhgHCxgHg0YBP?= =?us-ascii?q?oEQB4Ufo2iEP4J5hz0OGYkMB0MUAQEBAQEBAQEBAQESAQEJDQkIJjGCMyKCbQQ?= =?us-ascii?q?ZARseAxIDDTcCJAERAQUBIoopAQMVEJFhjVWDRT+MCoFsGAUBHIMIBYNjChknD?= =?us-ascii?q?VaDUQIGEoEMggmLd4RXFoJLAQSBLAEBlXuHUwgBAYFNkjiCDIVKg3GGV0iLY4d?= =?us-ascii?q?AFB+BFTaBK1IjeFuBV4RlJDaJAwEBAQ?= X-IPAS-Result: =?us-ascii?q?A0DzCAD+bV1ZgDTVVdFcHhgHCxgHg0YBPoEQB4Ufo2iEP4J?= =?us-ascii?q?5hz0OGYkMB0MUAQEBAQEBAQEBAQESAQEJDQkIJjGCMyKCbQQZARseAxIDDTcCJ?= =?us-ascii?q?AERAQUBIoopAQMVEJFhjVWDRT+MCoFsGAUBHIMIBYNjChknDVaDUQIGEoEMggm?= =?us-ascii?q?Ld4RXFoJLAQSBLAEBlXuHUwgBAYFNkjiCDIVKg3GGV0iLY4dAFB+BFTaBK1Ije?= =?us-ascii?q?FuBV4RlJDaJAwEBAQ?= X-IronPort-AV: E=Sophos;i="5.40,314,1496095200"; d="scan'208,217";a="282227799" Received: from mail-vk0-f52.google.com ([209.85.213.52]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 06 Jul 2017 00:55:55 +0200 Received: by mail-vk0-f52.google.com with SMTP id 191so869975vko.2 for ; Wed, 05 Jul 2017 15:55:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=rBz6LVjuXHTpOGeXXoDYw/k7AacAv4vEtPQZDWNEfC8=; b=RxkescVYD7xK2pgeAI8BJzizzj6kW8IVnSASoXpgnWr9H4hKtZr+vFm96Q6HMWvfKX d7AyckIAhhm/LHU9U74PiUQ0BxY8/KFjn2kUtN0AHPkmBGWxov6ird7m1GaZmwuWZgY1 0Ca2BAMzB6ecC+M44yQVLld8Lw4biy5uNEfB1+wsidKVNAfG7JZkHgc3XuTZj3QEd1JI KSmQX9OJ9JZ4twOZo+z8MGP/o7POqZ5nUhZ4vS+OeEjsGccl2VuK6gd8Q+c2ogfWKhNR A6anEgbVKwUHE16Dz2igaPdw58GTS4h5t2xSKFP++B5M2Ze4Wyn6wCOWgBi/+zMMpJBi 4IEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=rBz6LVjuXHTpOGeXXoDYw/k7AacAv4vEtPQZDWNEfC8=; b=huePZpqLcUG+zJ8tjauSUoRET2t+tmzeFqnw2w8/PC7QT6a1y4xXK2XqGDPTE5nPtR Jed2WLSxggOyWGi4tqZv33FtWLmlwkI2mI9UP3UiKs+ZXUyLZR7jhSjnn3W/NiZhGCRs Puf1zHA5LTpMPquoZSEeVd9j9K/3XVOKt4T0hPaoYOmCL0bObF4UX4z0mmfqOYJd+65f EW61QxPh/Jgi5i4Tkr4Q364ZeMYDfhmPTwZN7YHZQ4AKvR+JQEDzlQjf8nz5Se3EmLgH WVWs8+SFJB7UImXv1kzZ6lW2p1o4YL/XqJNZZ2HKY6ZNOi4EvmuXwMHBuWtG2rrkuxFz 26Dw== X-Gm-Message-State: AKS2vOxsA5KVKkAKlrsR9YqztKRsJ4TGLEebBy0PwUe1X4KqSzaPu5EV NthLG2VV8ruKt/cmyl1PRXWZcIZ5/XIW X-Received: by 10.31.108.199 with SMTP id j68mr26053395vki.106.1499295354434; Wed, 05 Jul 2017 15:55:54 -0700 (PDT) MIME-Version: 1.0 Received: by 10.176.81.41 with HTTP; Wed, 5 Jul 2017 15:55:34 -0700 (PDT) From: Shayne Fletcher Date: Wed, 5 Jul 2017 18:55:34 -0400 Message-ID: To: "caml-list@inria.fr users" Content-Type: multipart/alternative; boundary="001a11478efc03bf03055399e7b2" Subject: [Caml-list] [Async / Cohttp_async] Problem getting all of the data in a response body --001a11478efc03bf03055399e7b2 Content-Type: text/plain; charset="UTF-8" Can anyone help me out with this? In short, I'm doing a HTTP POST with a handler along the lines of: ``` fun ((resp : Cohttp_async.Response.t) , (body : Cohttp_async.Body.t)) : unit Or_error.t -> let r : string Async.Pipe.Reader.t = Cohttp_async.Body.to_pipe body in let _ = Async.Pipe.iter r ~continue_on_error:true ~f:(fun s -> Async.return (printf "%s" s)) in (Ok () : unit Or_error.t) ``` Each time I invoke the program I get, more or less output (very occasionally none) but never all of it. The response header says it's "fixed 2700816" and indeed, if I replace the code above with ``` fun ((resp : Cohttp_async.Response.t) , (body : Cohttp_async.Body.t)) : unit Or_error.t -> let r : string Async.Pipe.Reader.t = Cohttp_async.Body.to_pipe body in let n : int Deferred.t = Async.Pipe.fold r ~init:0 ~f:(fun acc s -> printf "acc : %d\n" acc; Async.return (acc + String.length s) ) in let _ : unit Deferred.t = n >>| fun n -> printf "Chars read : %d" n in (Ok () : unit Or_error.t) ``` then (for example), on the first run I might see ``` acc : 0 acc : 1118 acc : 7503 acc : 8780 ``` and then on the second run I might see ``` acc : 0 acc : 1118 acc : 4949 ``` but never have I seen "Chars read : 2700816". I've tried a bunch of different things: - `Pipe.read_all`: ``` let _ = Async.Pipe.read_all r >>| fun q -> Queue.iter q ~f:(fun s -> printf "%s" s) in ... ``` No output. - `Pipe.drain_and_count`: ``` let _ = Async.Pipe.drain_and_count r >>| fun n -> printf "Count %d\n" n in ... ``` No output. - `Pipe.to_list`: ``` let _ = Async.Pipe.to_list r >>| fun l -> printf "%s" (String.concat ~sep:"" l) in ... ``` No output. Also tried the obvious: - `Cohttp_async.Body.to_string`: ``` let s = Cohttp_async.Body.to_string body in let _ = s >>| fun s -> printf "%s" s in ... ``` No output. I'm new to this and obviously missing something fundamental :) Is there a kind soul out there who can give me a hint on how to proceed please? Thanks! -- Shayne Fletcher --001a11478efc03bf03055399e7b2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
= Can anyone help me out with this?<= /div>

In= short, I'm doing a HTTP POST with a handler along the lines of:=
```
fu= n ((resp : Cohttp_async.Response.t)
=C2=A0 =C2=A0 , (body : Cohttp_async.Bo= dy.t)) : unit Or_error.t ->
=C2=A0 =C2=A0 =C2=A0let r : string Async.Pip= e.Reader.t =3D Cohttp_async.Body.to_pipe body in
=C2=A0 =C2=A0 =C2=A0let _ = =3D
=C2=A0 =C2=A0 =C2=A0 Async.Pipe.iter
=C2=A0 =C2=A0 =C2=A0 =C2=A0 r
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 ~continue_on_error:true
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 ~f:(fun s -> Async.return (printf "%s" s)) in
=
=C2=A0 =C2= =A0 =C2=A0 (Ok () : unit Or_error.t)

```

Each time I invoke the pr= ogram I get, more or less output (very occasionally none) but never all of = it.=C2=A0The response = header says it's "fixed =C2=A02700816" and indeed, if I repla= ce the code above with
```
fun ((resp : Cohttp_async.Response.t)
=C2=A0 = =C2=A0 , (body : Cohttp_async.Body.t)) : unit Or_error.t ->
=
=C2=A0 let r= : string Async.Pipe.Reader.t =3D Cohttp_async.Body.to_pipe body in<= /div>
=C2=A0 = let n : int Deferred.t =3D
=C2=A0 =C2=A0 Async.Pipe.fold
=C2=A0 =C2=A0 =C2= =A0 r
=C2=A0 =C2=A0 =C2=A0 ~init:0
=C2=A0 =C2=A0 =C2=A0 ~f:(fun acc s ->=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf "acc : %d\n" ac= c; Async.return (acc + String.length s)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = ) in
=C2=A0 let _ : unit Deferred.t =3D n =C2=A0>>| fun n -> print= f "Chars read : %d" n in
=C2=A0 (Ok () : unit Or_error.t)<= /div>

=C2= =A0```
then (for example), on the first run I might see
```
acc : 0<= /div>
acc : 1= 118
acc : 7503
acc : 8780

```
=
and then on the second run I might s= ee
```
acc : 0
acc : 1118
acc : 4949

```
but never have I seen "Ch= ars read : 2700816".

I've tried a bunch of different things:<= /font>
=
=C2=A0 - `Pipe.read_all`:
=C2=A0 =C2=A0 =C2=A0```
=C2=A0 =C2=A0 =C2=A0= =C2=A0let _ =3D
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Async.Pipe.read_all r &g= t;>|
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fun q -> Queue.iter q ~f:(fun = s -> printf "%s" s) in
=C2=A0 =C2=A0 =C2=A0 =C2=A0...

=C2= =A0 =C2=A0 =C2=A0```
=C2=A0 =C2=A0 =C2=A0No output.
=C2=A0 =C2=A0 =C2=A0
= =C2=A0 - `Pipe.drain_and_count`:
<= font face=3D"tahoma, sans-serif">=C2=A0 =C2=A0 ```
=C2=A0 =C2=A0 =C2=A0 l= et _ =3D
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Async.Pipe.drain_and_count r >>|=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 fun n -> printf "Count %d\n" n in=
=C2=A0 =C2=A0 =C2=A0 ...

=C2=A0 =C2=A0 ```
=C2=A0 =C2=A0 No output.
= =C2=A0=C2=A0
=C2=A0 - `Pipe.to_list`:
=C2=A0 =C2=A0 =C2=A0```
<= div class=3D"gmail_default">=C2=A0 =C2=A0= =C2=A0let _ =3D
=C2=A0 =C2=A0 =C2=A0 =C2=A0Async.Pipe.to_list r >>|<= /font>
= =C2=A0 =C2=A0 =C2=A0 =C2=A0fun l -> printf "%s" (String.concat= ~sep:"" l) in
=C2=A0 =C2=A0 =C2=A0...

=C2=A0 =C2=A0 =C2=A0``= `
<= font face=3D"tahoma, sans-serif">=C2=A0=C2=A0
Also tried the obvious:
=C2=A0 - `Cohttp_async.Body.to_string`:
=C2=A0 =C2=A0 ```
=C2=A0 =C2=A0 = =C2=A0 let s =3D Cohttp_async.Body.to_string body in
=C2=A0 =C2=A0 =C2=A0 l= et _ =3D s >>| fun =C2=A0s -> printf "%s" s in
=C2=A0 = =C2=A0 =C2=A0 ...

=C2=A0 =C2=A0 ```
=C2=A0 =C2=A0 No output.

I'= ;m new to this and obviously missing something fundamental :) Is there a ki= nd soul out there who can give me a hint on how to proceed please?

Thanks!


--
Shayne Fletcher
--001a11478efc03bf03055399e7b2--