From f4389bc575610ab6cabcc0a034ae5a3b92739f60 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Tue, 7 Jan 2003 17:07:22 +0000 Subject: [PATCH] - support file:// URL scheme in http_get --- helm/http_getter/http_getter_misc.ml | 18 +++++++++++++++--- helm/http_getter/http_getter_misc.mli | 3 ++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/helm/http_getter/http_getter_misc.ml b/helm/http_getter/http_getter_misc.ml index 880ddd46e..1ec7101c8 100644 --- a/helm/http_getter/http_getter_misc.ml +++ b/helm/http_getter/http_getter_misc.ml @@ -122,7 +122,19 @@ let string_of_proc_status = function | Unix.WSTOPPED sg -> sprintf "[Stopped: %d]" sg let http_get url = - try - Some (Http_client.Convenience.http_get url) - with Http_client.Http_error (code, _) -> None + if Pcre.pmatch ~rex:file_scheme_RE url then begin + (* file:// URL. Read data from file system *) + let fname = Pcre.replace ~rex:file_scheme_RE url in + try + let size = (Unix.stat fname).Unix.st_size in + let buf = String.create size in + let ic = open_in fname in + really_input ic buf 0 size; + close_in ic; + Some buf + with Unix.Unix_error (Unix.ENOENT, "stat", _) -> None + end else (* other URL, pass it to netclient *) + try + Some (Http_client.Convenience.http_get url) + with Http_client.Http_error (code, _) -> None diff --git a/helm/http_getter/http_getter_misc.mli b/helm/http_getter/http_getter_misc.mli index d9f8ff873..94c5dc5a9 100644 --- a/helm/http_getter/http_getter_misc.mli +++ b/helm/http_getter/http_getter_misc.mli @@ -56,6 +56,7 @@ val mkdir: ?parents: bool -> string -> unit val string_of_proc_status : Unix.process_status -> string (** raw HTTP downloader, return Some the contents of downloaded resource or - None if an error occured while downlaoding *) + None if an error occured while downloading. This function support also + "file://" scheme for filesystem resources *) val http_get: string -> string option -- 2.39.2