From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 7D470BC57 for ; Tue, 21 Sep 2010 21:58:53 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArIAAPWqmExCbwQakWdsb2JhbACiKhUBAQEBCQsKBxEEHsRyBYVBhFKIaA X-IronPort-AV: E=Sophos;i="4.56,401,1280700000"; d="scan'208";a="70298830" Received: from out2.smtp.messagingengine.com ([66.111.4.26]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 21 Sep 2010 21:58:52 +0200 Received: from compute3.internal (compute3.nyi.mail.srv.osa [10.202.2.43]) by gateway1.messagingengine.com (Postfix) with ESMTP id 9D72B56D; Tue, 21 Sep 2010 15:58:51 -0400 (EDT) Received: from frontend1.messagingengine.com ([10.202.2.160]) by compute3.internal (MEProxy); Tue, 21 Sep 2010 15:58:51 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=messagingengine.com; h=message-id:date:from:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; s=smtpout; bh=szkREf3OuEBzfd7LyssBPXVZvNk=; b=J+ix9QPsv1iIY42pN7RonOFfjo3cz6K+WA9Q9I1PMGmn7Q/K/tBA0yasgqtTvEkIFjVhpWeeOr+ucebpTAL2dTrrUWQczL+0W4kGrq6h3NDgtXHF1MXRwajqqfbjZREJEGk2IEPlDPQTmvm1SI1aTexiz88TZC0pNCvcH5swOlo= X-Sasl-enc: 4zB7lv3fyfU0EAJX54y29Qwirh7YYH52nh0ZmiEHHXpa 1285099131 Received: from [192.168.1.61] (64-71-1-165.static.wiline.com [64.71.1.165]) by mail.messagingengine.com (Postfix) with ESMTPSA id 22473400597; Tue, 21 Sep 2010 15:58:51 -0400 (EDT) Message-ID: <4C990E79.9050105@ens-lyon.org> Date: Tue, 21 Sep 2010 12:58:49 -0700 From: Martin Jambon User-Agent: Thunderbird 2.0.0.22 (X11/20090908) MIME-Version: 1.0 To: Richard Jones Cc: ben kuin , caml-list@inria.fr Subject: Re: [Caml-list] web server interface for Ocaml ( like rack, wsgi, ...)? References: <20100919103258.GA14826@annexia.org> <20100921192048.GA25700@annexia.org> In-Reply-To: <20100921192048.GA25700@annexia.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ens-lyon:01 ocaml:01 0200,:01 ocamlnet:01 compilation:01 ocaml:01 wikipedia:01 lambda:01 usr:01 ocamlrun:01 ocamlnet:01 gerd:01 netcgi:01 ocamlfind:01 usr:01 Richard Jones wrote: > On Tue, Sep 21, 2010 at 09:50:36AM +0200, ben kuin wrote: >>> what's wrong with simply proxying the HTTP connections through your favorite webserver to the backend ocsigen/ocamlnet server? >> Nothing per se. I've tried so set something up with ocsigen, but I had >> to give up. There seems to be a certain philosophy behind it how you >> should writing web apps. >> >> But I just wanted to do something: >> - small ( one page app ) >> - quick and dirty ( no big setup upfront, no compilation) >> - deployment, by dropping a (ocaml script) into a webroot, not matter >> what webserver is running >> - permissive license ( mit, ...) > >> ~~~~ from wikipedia ~~~~ >> require 'rack' >> app = Rack::Builder.app do >> lambda do |env| >> body = "Hello, World!" >> [200, {"Content-Type" => "text/plain", "Content-Length" => >> body.length.to_s}, [body]] >> end >> end > > This ought to work, and it's pretty simple ... > > ----- > #!/usr/bin/ocamlrun ocaml > print_string "\ > Content-Type: text/plain > > Hello, World!" > ----- > > 'course the problem is you'll be wanting to parse parameters, cookies > and the rest of it, and there it does get a little bit more > complicated. > > I'm fairly sure ocamlnet can write standalone scripts like that? Gerd?? I am pretty sure this is possible to do with Ocamlnet (netcgi2) although I haven't done it in a while. My recommendation would be to use ocamlscript, which relies on ocamlfind to load libraries and compiles the executables only when needed, based on timestamps. http://martin.jambon.free.fr/ocamlscript.html You can try this: #! /usr/bin/env ocamlscript Ocaml.packs := [ "netcgi2" ] -- let handle_request (cgi : Netcgi.cgi) = cgi # set_header ~content_type:"text/plain" (); cgi # output # output_string "Hello!\n"; cgi # output # commit_work () let () = if Netcgi_cgi.is_cgi () then Netcgi_cgi.run handle_request else Netcgi_test.run handle_request I don't know if it works when called from apache. There might be permission issues. In general I think it's a bad idea to let the webserver do the precious program analysis (compilation) in a live installation, but it's free to try. Ocamlscript also has an option to just compile the script and takes care of cleaning up the compilation by-products. Martin -- http://mjambon.com/