X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Focaml-http%2Fhttp_client.ml;h=1a89bba8aa6d525dc0bd84d4b21723efe9ea15f2;hb=0c6a5aadb1a7746681a8e26fc0b009f847c10557;hp=f903add7a51ad3333ef77a756ab3571be68206ac;hpb=1fe9e592b22274b7ab6bbbab8e29135993523c1c;p=helm.git diff --git a/helm/DEVEL/ocaml-http/http_client.ml b/helm/DEVEL/ocaml-http/http_client.ml index f903add7a..1a89bba8a 100644 --- a/helm/DEVEL/ocaml-http/http_client.ml +++ b/helm/DEVEL/ocaml-http/http_client.ml @@ -2,7 +2,7 @@ (* OCaml HTTP - do it yourself (fully OCaml) HTTP daemon - Copyright (C) <2002-2003> Stefano Zacchiroli + Copyright (C) <2002-2004> Stefano Zacchiroli 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 @@ -52,14 +52,28 @@ let init_socket addr port = let inchan = Unix.in_channel_of_descr suck in (inchan, outchan) -let http_get_iter callback url = +let submit_request kind url = let (address, port, path) = parse_url url in - let buf = String.create tcp_bufsiz in let (inchan, outchan) = init_socket address port in - output_string outchan (sprintf "GET %s HTTP/1.0\r\n" path); + let req_string = match kind with `GET -> "GET" | `HEAD -> "HEAD" in + output_string outchan (sprintf "%s %s HTTP/1.0\r\n" req_string path); output_string outchan (sprintf "Host: %s\r\n\r\n" address); - flush outchan; + (inchan, outchan) + +let http_head url = + let (inchan, outchan) = submit_request `HEAD url in + let (_, status) = Http_parser.parse_response_fst_line inchan in + (match code_of_status status with + | 200 -> () + | code -> raise (Http_error (code, ""))); + let buf = Http_misc.buf_of_inchan inchan in + close_in inchan; (* close also outchan, same fd *) + Buffer.contents buf + +let http_get_iter 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 -> ()