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 900788018B for ; Thu, 6 Jul 2017 07:23:59 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=nicolas.ojeda.bar@lexifi.com; spf=SoftFail smtp.mailfrom=nicolas.ojeda.bar@lexifi.com; spf=None smtp.helo=postmaster@vrout10.yaziba.net Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of nicolas.ojeda.bar@lexifi.com) identity=pra; client-ip=185.56.204.56; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="nicolas.ojeda.bar@lexifi.com"; x-sender="nicolas.ojeda.bar@lexifi.com"; x-conformance=sidf_compatible Received-SPF: SoftFail (mail2-smtp-roc.national.inria.fr: domain of nicolas.ojeda.bar@lexifi.com is inclined to not designate 185.56.204.56 as permitted sender) identity=mailfrom; client-ip=185.56.204.56; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="nicolas.ojeda.bar@lexifi.com"; x-sender="nicolas.ojeda.bar@lexifi.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@vrout10.yaziba.net) identity=helo; client-ip=185.56.204.56; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="nicolas.ojeda.bar@lexifi.com"; x-sender="postmaster@vrout10.yaziba.net"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3A54KXWBe2oP2lSRjSvmYwaKk7lGMj4u6mDksu8pMi?= =?us-ascii?q?zoh2WeGdxcW+ZB7h7PlgxGXEQZ/co6odzbGH7Oa4ASQp2tWoiDg6aptCVhsI24?= =?us-ascii?q?09vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/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l/+Lu?= =?us-ascii?q?jWM+mVIFYaamx54XaHShEvRiIkWZembsj8waEWYKuwo+VPblhEeDUT5VfXayXr?= =?us-ascii?q?gz6is1CIK8FYvDQ4etj6Gf0yqjBZ1WY3xGCkiLEXf1a4XXE8sLPRmSK95nn3Qq?= =?us-ascii?q?UbW9QI8sz1n6rw/z2rxqaOTQ9zETtZ/5koUtz+LWnBA2szdzCpLO/XuKSjRSn2?= =?us-ascii?q?gPQ7Yt64d9rEB0/X0Py+Ashf1TEtha/LVOUAo2PNjWxvZSD93iWwzAONyOTQD1?= =?us-ascii?q?EZ2dHTgtQ4dpkJc1aEFnFoDn10ib0g=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0BtAwCGyF1ZfTjMOLlcSQYMhBGBEAeFH?= =?us-ascii?q?4lWkHYQiB6PZieFdQKDFkoUAQEBAQEBAQEBAQESAQELFAhXgjMkAYJBAQICASM?= =?us-ascii?q?EUgULCQILNwICIQESAQUBHAYTihcDDQgEAQuSEpEaP4wKgWw6hzwNg30BAQEBB?= =?us-ascii?q?gEBAQEBAQEhgR6CCYhRgldPhFcWgksBBJcshyQ7jxuEaoIMhUqDcYZXSIstN4d?= =?us-ascii?q?CFB+BEwI2gSt1XhoGgiyCRxwZgVB0AYkCAQEB?= X-IPAS-Result: =?us-ascii?q?A0BtAwCGyF1ZfTjMOLlcSQYMhBGBEAeFH4lWkHYQiB6PZie?= =?us-ascii?q?FdQKDFkoUAQEBAQEBAQEBAQESAQELFAhXgjMkAYJBAQICASMEUgULCQILNwICI?= =?us-ascii?q?QESAQUBHAYTihcDDQgEAQuSEpEaP4wKgWw6hzwNg30BAQEBBgEBAQEBAQEhgR6?= =?us-ascii?q?CCYhRgldPhFcWgksBBJcshyQ7jxuEaoIMhUqDcYZXSIstN4dCFB+BEwI2gSt1X?= =?us-ascii?q?hoGgiyCRxwZgVB0AYkCAQEB?= X-IronPort-AV: E=Sophos;i="5.40,315,1496095200"; d="scan'208,217";a="282252109" Received: from vrout10-bl2.yaziba.net (HELO vrout10.yaziba.net) ([185.56.204.56]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 06 Jul 2017 07:23:58 +0200 Received: from mtaout10.int.yaziba.net (mtaout10.int.yaziba.net [10.4.20.36]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by vrout10.yaziba.net (mx10.yaziba.net) with ESMTPS id DFAFA52032 for ; Thu, 6 Jul 2017 07:23:57 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mtaout10.int.yaziba.net (Postfix) with ESMTP id 0F2B21601F4 for ; Thu, 6 Jul 2017 07:23:58 +0200 (CEST) X-Virus-Scanned: amavisd-new at Received: from mtaout10.int.yaziba.net ([127.0.0.1]) by localhost (mtaout10.int.yaziba.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id jwjvYLM1EkUL for ; Thu, 6 Jul 2017 07:23:57 +0200 (CEST) Received: from mail-qt0-f178.google.com (mail-qt0-f178.google.com [209.85.216.178]) by mtaout10.int.yaziba.net (Postfix) with ESMTPSA id A7A111600D1 for ; Thu, 6 Jul 2017 07:23:57 +0200 (CEST) Received: by mail-qt0-f178.google.com with SMTP id r30so7253184qtc.0 for ; Wed, 05 Jul 2017 22:23:57 -0700 (PDT) X-Gm-Message-State: AKS2vOyMqF303SYS3Q2NBf7dIKkQAHRy8bAs1IPZjqL4hKu3y6GM7yQS VDFbxFKhhf4ZlbAZGknl/x0beODosw== X-Received: by 10.237.50.4 with SMTP id y4mr58333490qtd.225.1499318636616; Wed, 05 Jul 2017 22:23:56 -0700 (PDT) MIME-Version: 1.0 Received: by 10.200.34.98 with HTTP; Wed, 5 Jul 2017 22:23:36 -0700 (PDT) In-Reply-To: References: From: =?UTF-8?Q?Nicol=C3=A1s_Ojeda_B=C3=A4r?= Date: Thu, 6 Jul 2017 07:23:36 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Shayne Fletcher Cc: "caml-list@inria.fr users" Content-Type: multipart/alternative; boundary="94eb2c12446abda00505539f52e2" X-DRWEB-SCAN: ok X-VRSPAM-SCORE: -100 X-VRSPAM-STATE: legit X-VRSPAM-CAUSE: gggruggvucftvghtrhhoucdtuddrfeelkedrudejgddutdegucetufdoteggodetrfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpegjfhfhfffkuffvtgesrgdtreertddtjeenucfhrhhomheppfhitgholhojshgpqfhjvggurggpueomrhcuoehnihgtohhlrghsrdhojhgvuggrrdgsrghrsehlvgigihhfihdrtghomheqnecuffhomhgrihhnpehpihhpvgdpphhiphgvrdhtohdpphhiphgvrdhrvggrugdpshhtrhhinhhgnecukfhppedvtdelrdekhedrvdduiedrudejkeenucfrrghrrghmpehmohguvgepshhmthhpohhuth X-VRSPAM-EXTCAUSE: mhhouggvpehsmhhtphhouhht Subject: Re: [Caml-list] [Async / Cohttp_async] Problem getting all of the data in a response body --94eb2c12446abda00505539f52e2 Content-Type: text/plain; charset="UTF-8" Hi Shayne, I am not very familiar with Async, but did you remember to run the scheduler (Scheduler.go () or similar) ? Cheers, Nicolas On Thu, Jul 6, 2017 at 12:55 AM, Shayne Fletcher < shayne.fletcher.50@gmail.com> wrote: > 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 > --94eb2c12446abda00505539f52e2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Shayne,

I am not very familiar with = Async, but did you remember to run the scheduler (Scheduler.go () or simila= r) ?

Cheers,
Nicolas


On Thu, Ju= l 6, 2017 at 12:55 AM, Shayne Fletcher <shayne.fletcher.50@gmai= l.com> wrote:
Can anyone help me out with this?

In short, I'= ;m doing a HTTP POST with a handler along the lines of:
```
fun ((resp : Co= http_async.Response.t)
=C2=A0 =C2=A0 , (body : Cohttp_async.Body.t)) : uni= t Or_error.t ->
=C2=A0 =C2=A0 =C2=A0let r : string Async.Pipe.Reader.t = =3D Cohttp_async.Body.to_pipe body in
=C2=A0 =C2=A0 =C2=A0let _ =3D<= /div>
=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 program I get, = more or less output (very occasionally none) but never all of it.=C2=A0The response header says i= t's "fixed =C2=A02700816" and indeed, if I replace the code a= bove 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
=C2=A0 let n : int Def= erred.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" acc; 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 -> printf "Chars r= ead : %d" n in
=C2=A0 (Ok () : unit Or_error.t)

=C2=A0```
then (fo= r example), on the first run I might see
```
acc : 0
acc : 1118
acc : 7503<= /font>
= acc : 8780

```

and then on the second run I might see
=
```
acc : 0<= /font>
= acc : 1118
acc : 4949

```
but never have I seen "Chars read : 27= 00816".

I've tried a bunch of different things:
<= div class=3D"gmail_default">
=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 >>|
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fun q -> Queue.iter q ~f:(fun s -> pri= ntf "%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
<= div class=3D"gmail_default">=C2=A0 - `Pip= e.drain_and_count`:
=C2=A0 =C2=A0 ```
=C2=A0 =C2=A0 =C2=A0 let _ =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 ```
<= font face=3D"tahoma, sans-serif">=C2=A0 =C2=A0 No output.
=C2=A0=C2=A0
=C2= =A0 - `Pipe.to_list`:
=C2=A0 =C2=A0 =C2=A0```
=C2=A0 =C2=A0 =C2=A0let _ = =3D
=C2=A0 =C2=A0 =C2=A0 =C2=A0Async.Pipe.to_list r >>|
<= div class=3D"gmail_default">=C2=A0 =C2=A0= =C2=A0 =C2=A0fun l -> printf "%s" (String.concat ~sep:"&= quot; l) in
=C2=A0 =C2=A0 =C2=A0...

=C2=A0 =C2=A0 =C2=A0```
=C2=A0 =C2= =A0 =C2=A0No output.
=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 let _ =3D s &= gt;>| 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 th= is and obviously missing something fundamental :) Is there a kind soul out = there who can give me a hint on how to proceed please?

Than= ks!

=

-= -
Shayne Fletcher

--94eb2c12446abda00505539f52e2--