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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id D81B87F0BA for ; Mon, 29 Aug 2016 17:39:49 +0200 (CEST) IronPort-PHdr: 9a23:6DSSXRCDzh0pedSlHxjTUyQJP3N1i/DPJgcQr6AfoPdwSP/5osbcNUDSrc9gkEXOFd2CrakV0qyK7+uwBSRAuc/H6yFaNsQUFlcssoY/p0QYGsmLCEn2frbBThcRO4B8bmJj5GyxKkNPGczzNBX4q3y26iMOSF2kbVImbtr8FoOatcmrzef6o8SVOFQRwmbhKuMuZFXu9EOK55FQ2dMjYo8KiTLx6kNSfOpXwW46bXmypD3bovmKwZh47i5LsOgg/cMTGY/zfqA/UKAKRG9+azN9zITRuBLCVQqC4GcHGiVTy0IQQlvz1wzhRpr6rgf9s+N83mHaYZy3HvgIXmGO5r1qT1fUhSYXOj8j+SmDhsVqjaUdvB+gtxF+2Yf8ZoWYJeZzeOXWetZMFkRbWcMEbTFNA8uTdYoJBecbMq4MtZTxph0Btxq4DwS2C8vgzzZJgjn92qhsgLdpKh3PwAF1R4FGi3/TttigcfpLXA== Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=rudi.grinberg@gmail.com; spf=Pass smtp.mailfrom=rudi.grinberg@gmail.com; spf=None smtp.helo=postmaster@mail-it0-f49.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of rudi.grinberg@gmail.com) identity=pra; client-ip=209.85.214.49; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="rudi.grinberg@gmail.com"; x-sender="rudi.grinberg@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of rudi.grinberg@gmail.com designates 209.85.214.49 as permitted sender) identity=mailfrom; client-ip=209.85.214.49; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="rudi.grinberg@gmail.com"; x-sender="rudi.grinberg@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-it0-f49.google.com) identity=helo; client-ip=209.85.214.49; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="rudi.grinberg@gmail.com"; x-sender="postmaster@mail-it0-f49.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CXAgBGVsRXhjHWVdFcGwEBAQMBAQEWAQEBAwEBAYMKAQEBAQF1fKZOhg2NTiSCMoNHAoFMPBABAQEBAQEBAQEBARIBAQEICwsJGS+CMgQBFQWCEQEBBBIRBBEIARsSCwEDDAYFGAICBQQdAgIPBQ8RAQUBChglEIgDAQMXDqAggTI+Mos8gWqCXgWGTAoZJwMKVIJ6AQEBAQEBAQMBAQEBAQEZAgYQc4MggguETYQqgxiCWgWGYgyNGoVHgWSEPIkBCoI7hxKGCI58MYEQNYJGHoFzVIUMgUABAQE X-IPAS-Result: A0CXAgBGVsRXhjHWVdFcGwEBAQMBAQEWAQEBAwEBAYMKAQEBAQF1fKZOhg2NTiSCMoNHAoFMPBABAQEBAQEBAQEBARIBAQEICwsJGS+CMgQBFQWCEQEBBBIRBBEIARsSCwEDDAYFGAICBQQdAgIPBQ8RAQUBChglEIgDAQMXDqAggTI+Mos8gWqCXgWGTAoZJwMKVIJ6AQEBAQEBAQMBAQEBAQEZAgYQc4MggguETYQqgxiCWgWGYgyNGoVHgWSEPIkBCoI7hxKGCI58MYEQNYJGHoFzVIUMgUABAQE X-IronPort-AV: E=Sophos;i="5.28,597,1464645600"; d="scan'208";a="191399266" Received: from mail-it0-f49.google.com ([209.85.214.49]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 29 Aug 2016 17:39:48 +0200 Received: by mail-it0-f49.google.com with SMTP id g62so104459677ith.1 for ; Mon, 29 Aug 2016 08:39:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=t0QvKWkWdurZ25yFjLp+qODJ7LtEDZT2bbaZePtmMEQ=; b=zREc6mPVLVr6DFjQSXo6YyzTNXRa5hI0igkQJN8BcFv9I2zuMu9Rdl8S5A/NP0h94n uO1Wo9ySlj5tbmxgZeS66hHNmwiaFqkNXPfvTnJRrcHbMtIZmZw2HxqOoi+c5wO7PI3L edn5v37LwLoG2WHES500dKL9DnVF4n2Ddzt6xjc8qxIBNd38QmNr482LZYbfYhTsmGnx RPfkRGzqXfQBYu+MQUsU3o24N3gEH8iB2Y9pSBQpzJVWdA/BsHZP4NPN6DfucsXAIv5H ErCgZ0IirVTgU2C+IVqs2VN+VfIO3hEfk8dXDz1xtof6OWHmJXAMcwSt7g8mxJxp83w4 wu8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=t0QvKWkWdurZ25yFjLp+qODJ7LtEDZT2bbaZePtmMEQ=; b=lVRnFLVXhCuCGwMHBS8Lel++0QlxUZiHh0S3Iwi6lFZPxwy1wpVFWmY/qxuOx5VNZk wtXy/AgMcTDkK19LQwXxfsTMpcj2bxh3WondycZWxhLqvHKXPgquhDek0ZP30gKCW3Zc D+m6JlViW20AWSRSXtATikCBolKhlBwj43kHRJ7FNoQkZWkdig/o4ONowPvf6ii4KigZ ddp9H4XjJGr4Wv2pmG3AEtoH5/f486faFJbz3cKueRDjk8mbOH8lQxUYf+i0wVxu8Um9 anIAyEVk6RZcZx+idd0WL5yG6Eakp1Kl5XRELRWXZWFKq3p3LGPvyrmq8BpOmvOoybv3 MOKQ== X-Gm-Message-State: AE9vXwNg+QD8txw+0ry8k/8dqWVzrRJYuR5jQSyQ3bj1wNMFltIKBAOUQUkG37RE5NjJsA== X-Received: by 10.36.26.70 with SMTP id 67mr17380795iti.4.1472485187045; Mon, 29 Aug 2016 08:39:47 -0700 (PDT) Received: from localhost (24-246-56-85.cable.teksavvy.com. [24.246.56.85]) by smtp.gmail.com with ESMTPSA id d66sm6627646ith.9.2016.08.29.08.39.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Aug 2016 08:39:46 -0700 (PDT) Date: Mon, 29 Aug 2016 11:39:45 -0400 From: Rudi Grinberg To: Dario Teixeira Cc: caml-list Message-ID: <20160829153945.424bhlwpk7pmm6em@rgcaml.localdomain> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.2-neo (2016-08-19) Subject: Re: [Caml-list] Functorising over Cohttp's backends The Cohttp API at its present state doesn't really offer a good abstraction for creating backend independent HTTP clients and servers. Luckily, the request and response types are backend independent. And so is the http body type if you aren't streaming. This means that you can fairly easily create a light application specific abstraction for yourself. This means is that if you'd like to provide a backend independent server, you should just worry about providing 2 functions of the type: open Cohttp val lwt : Request.t -> Body.t -> (Response.t * Body.t) Lwt.t val async : Request.t -> Body.t -> (Response.t * Body.t) Deferred.t and perhaps provide some light wrappers for turning these into full blown cohttp servers in a backend dependent way. With this technique, Cohttp's API will only help you as far as manipulating request, response, and body values. This can often be enough for simple servers. But in cases where it's not, such as when you need access to the client FD for example Going back to implementing those 2 functions, you will need to cook up your own abstractions on top. Now going back to implementing the 2 functions mentioned above. For any non trivial server, you will need to find a way to share code between your Async and Lwt implementation. This is where it's common to use standard techniques such as functors. But that's a topic you know about just as much as I do :P To summarize, it's unfortunate that Cohttp doesn't provide a real server (or client) abstraction. But it's kind of hard to do without making a wrapper that tries to abstract away the differences between different backends. Hiding away the details of Async and Lwt was always an anti-goal for Cohttp anyway. Cheers, Rudi. On 08/29, Dario Teixeira wrote: >Hi, > >Suppose I have a function "make_callback" which creates a callback >ready to be given to Cohttp's Server.make. Here's its signature: > > type callback = > Cohttp_lwt_unix.Server.IO.conn * Cohttp.Connection.t -> > Cohttp.Request.t -> > Cohttp_lwt_body.t -> > (Cohttp.Response.t * Cohttp_lwt_body.t) Cohttp_lwt_unix.Server.IO.t > > val make_callback: unit -> callback > >Note that it's tied to the Lwt+Unix instantiation of Cohttp. Now, >I wish to make it more generic, so it can be used with the Async >backend, for instance. > >There's more to it than just using a functor for abstracting over the >IO monad, unfortunately. In particular, the connection type and the >body are also backend-dependent. Anyway, Cohttp's API is notoriously >hard to navigate. Is the generic signature I'm looking for already >defined somewhere, or are the backends so distinct that I might >as well forget about functorising the interface and thus force the >Lwt+Unix backend on my API? (It's the only backend I use myself...) > >Thanks in advance! >Best regards, >Dario Teixeira > > >-- >Caml-list mailing list. Subscription management and archives: >https://sympa.inria.fr/sympa/arc/caml-list >Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >Bug reports: http://caml.inria.fr/bin/caml-bugs