package simple_httpd

  1. Overview
  2. Docs

Module Simple_httpd.InputSource

Representation of input streams, can be generated from string, file, ...

Input streams are used to represent a series of bytes that can arrive progressively. For example, an uploaded file will be sent as a series of chunks.

Sourcetype t

A buffered stream, with a view into the current buffer (or refill if empty), and a function to consume n bytes.

Sourceval close : t -> unit

Close stream

Sourceval empty : t

Stream with 0 bytes inside

Sourceval make : ?bs:bytes -> ?close:(t -> unit) -> consume:(t -> int -> unit) -> fill:(t -> unit) -> unit -> t

make ~fill () creates a byte stream.

  • parameter fill

    is used to refill the buffer, and is called initially.

  • parameter close

    optional closing.

  • parameter init_size

    size of the buffer.

Sourceval of_chan : ?buf_size:int -> in_channel -> t

Make a buffered stream from the given channel.

Sourceval of_fd : ?buf_size:int -> Unix.file_descr -> t

Make a buffered stream from the given file descriptor.

Sourceval of_client : ?buf_size:int -> Client.t -> t

Make a buffered stream from the given http client's socket.

Sourceval of_io : ?buf_size:int -> Io.t -> t

Allow a to Make a buffered stream from the given Io.t. The call will be scheduled if read blocks.

Sourceval of_bytes : ?i:int -> ?len:int -> bytes -> t

A stream that just returns the slice of bytes starting from i and of length len.

Sourceval of_string : string -> t

Make a buffered stream from the given string

Sourcemodule type Output = sig ... end

Module type for filling an input buffer by printing. A module of this type is openned in <ML> section of .chamel file when using vfs_pack.

Sourceval of_output : ((module Output) -> unit) -> t

Make a buffered stream from a function that will call the echo and printf function from the provided module. Using effect, the function producing the output is called lazily when it is needed to fill the buffer.

Sourceval iter : (bytes -> int -> int -> unit) -> t -> unit

Iterate on the chunks of the stream.

Sourceval to_chan : out_channel -> t -> unit

Write the stream to the channel.

Sourceval with_file : ?buf_size:int -> string -> (t -> 'a) -> 'a

Open a file with given name, and obtain an input stream on its content. When the function returns, the stream (and file) are closed.

Sourceval end_of_input : t -> bool

returns true if we are at the end of the input (self.len = 0 and fill returns 0)

Sourceval eof : char

the chracter '\255'

Sourceval read_char : t -> char

read one char, returns Input.eof u=if the input buffer is empty

Sourceval read_line : buf:Buffer.t -> t -> string

Read a line from the stream.

  • parameter buf

    a buffer to (re)use. Its content will be cleared.

Sourceval really_input : t -> Bytes.t -> int -> int -> unit

really_input inp bytes off len reads exactly len bytes from inp and write then to bytes from offset may raise End_of_file of Invalid_argument if bytes is to small

Sourceval read_all : buf:Buffer.t -> t -> string

Read the whole stream into a string.

  • parameter buf

    a buffer to (re)use. Its content will be cleared.

Sourceval read_until : buf:Buffer.t -> target:string -> t -> unit

Advance in the stream until in meet the given target.

  • parameter buf

    a buffer to (re)use. Its content will be cleared.

Sourceval read_exactly : close_rec:bool -> size:int -> too_short:(int -> unit) -> t -> t

read_exactly ~size bs returns a new stream that reads exactly size bytes from bs, and then closes.

  • parameter close_rec

    if true, closing the resulting stream also closes bs

  • parameter too_short

    is called if bs closes with still n bytes remaining

Sourceexception FailParse of int

The following are a minimal set of non backtracking parsing combinators with no allocation. They use Input.eof when the stream is empty

Sourceval fail_parse : t -> 'a

fail, return the current offset

Sourceval branch_char : (char -> t -> 'a) -> t -> 'a

branch from the value of one char

Sourceval exact_char : char -> 'a -> t -> 'a

parse exactly one char

Sourceval exact_string : string -> 'a -> t -> 'a

parse exactly the given string

Sourceval charset : (char -> bool) -> t -> char
Sourceval star_fold : (t -> 'a) -> ('a -> 'b -> 'b) -> 'b -> t -> 'b
Sourceval plus_fold : (t -> 'a) -> ('a -> 'b -> 'b) -> 'b -> t -> 'b
Sourceval star : (t -> unit) -> t -> unit

repeat parsing 0 or more time, fail if partial parsing of one more item is possible

Sourceval plus : (t -> unit) -> t -> unit

repeat parsing 1 or more time, fail if partial parsing of one more item is possible

Sourceval blank : t -> unit

parse blank charaters

Sourceval space : t -> unit

parse spaces

Sourceval blanks : t -> unit
Sourceval int : t -> int

parse a positive integer in decimal

Sourceval peek_char : t -> char
Sourceval current : t -> string

return the current value of the buffer, usefull when capturing Fail_parse n