Plasma GitLab Archive
Projects Blog Knowledge

Module Http_fs


module Http_fs: sig .. end
HTTP filesystem


This module makes an HTTP file server accessible via a Netfs.stream_fs object, supporting

  • reading files
  • identifying and reading directories (if the server generates index pages for directories, see below for more information)
  • writing files (if the server implements PUT)
  • removing files (if the server implements DELETE)
One has to specify a base URL b, and the access of a file with path p is translated to the URL b ^ p. Note that p cannot include web parameters ("?" strings), and hash marks are also not supported.

A directory is recognized by appending a slash to the URL, and checking whether the URL exists.

The contents of a directory are determined by loading the directory URL, analyzing the HTML page, and checking for the presence of hyperlinks that do not contain slashes (or at most a trailing slash). Only hyperlinks of "A" elements are accepted.

Almost every web server can be configured to generate directory listings that conform to this format. For example, Apache provides this through the module mod_autoindex.

An extension to this would be support for WebDAV. This will be made available shortly as a separate library.

Examples



Read an HTTP directory:

       let fs = new http_fs ~streaming:true "http://localhost/~gerd"
       let files = fs # readdir [] "/"
    

Download a file into a string:

       let ch = fs # read [] "/file"
       let s = Netchannels.string_of_in_obj_channels ch
    

Copy a file hierarchy to the local disk:

       let lfs = Netfs.local_fs()
       Netfs.copy_into (fs :> Netfs.stream_fs) "/tree" lfs "/tmp"
    

Use globbing:

       let fsys = Netglob.of_stream_fs (fs :> Netfs.stream_fs)
       let files = Netglob.glob ~fsys (`String "/*.gif")
    


Extended stream_fs type



There is the new flag `Header for read and write, and the new method last_response_header for getting the response header of the most recently executed operation.
type read_flag = [ `Binary
| `Dummy
| `Header of (string * string) list
| `Skip of int64
| `Streaming ]
type write_flag = [ `Binary
| `Create
| `Dummy
| `Exclusive
| `Header of (string * string) list
| `Streaming
| `Truncate ]
class type http_stream_fs = object .. end

The class


class http_fs : ?config_pipeline:Http_client.pipeline -> unit -> ?streaming:bool -> ?tmp_directory:string -> ?tmp_prefix:string -> ?path_encoding:Netconversion.encoding -> ?enable_read_for_directories:bool -> string -> http_stream_fs
http_fs base_url: Accesses the HTTP file system rooted at base_url.
val http_fs : ?config_pipeline:(Http_client.pipeline -> unit) ->
?streaming:bool ->
?tmp_directory:string ->
?tmp_prefix:string ->
?path_encoding:Netconversion.encoding ->
?enable_read_for_directories:bool -> string -> http_stream_fs
Same as normal function
This web site is published by Informatikbüro Gerd Stolpmann
Powered by Caml