]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/ocaml-http/http_user_agent.ml
ocaml 3.09 transition
[helm.git] / helm / DEVEL / ocaml-http / http_user_agent.ml
index 5e74fbfafed50c2b5adc0a5841a69418dbd91f63..f5317d6858626fc3aa29c58a8a2e948b755ec819 100644 (file)
@@ -2,21 +2,21 @@
 (*
   OCaml HTTP - do it yourself (fully OCaml) HTTP daemon
 
-  Copyright (C) <2002-2004> Stefano Zacchiroli <zack@cs.unibo.it>
+  Copyright (C) <2002-2005> Stefano Zacchiroli <zack@cs.unibo.it>
 
   This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
+  it under the terms of the GNU Library General Public License as
+  published by the Free Software Foundation, version 2.
 
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
+  GNU Library General Public License for more details.
 
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software
-  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  You should have received a copy of the GNU Library General Public
+  License along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+  USA
 *)
 
 open Printf
@@ -71,14 +71,15 @@ let head url =
   close_in inchan; (* close also outchan, same fd *)
   Buffer.contents buf
 
-let get_iter callback url =
+let get_iter ?(head_callback = fun _ _ -> ()) callback url =
   let (inchan, outchan) = submit_request `GET url in
   let buf = String.create tcp_bufsiz in
   let (_, status) = Http_parser.parse_response_fst_line inchan in
   (match code_of_status status with
   | 200 -> ()
   | code -> raise (Http_error (code, "")));
-  ignore (Http_parser.parse_headers inchan);
+  let headers = Http_parser.parse_headers inchan in
+  head_callback status headers;
   (try
     while true do
       match input inchan buf 0 tcp_bufsiz with
@@ -93,8 +94,8 @@ let get_iter callback url =
   with End_of_file -> ());
   close_in inchan (* close also outchan, same fd *)
 
-let get url =
+let get ?head_callback url =
   let buf = Buffer.create 10240 in
-  get_iter (Buffer.add_string buf) url;
+  get_iter ?head_callback (Buffer.add_string buf) url;
   Buffer.contents buf