diff --git a/dev/tiny_httpd/Tiny_httpd_buf/index.html b/dev/tiny_httpd/Tiny_httpd_buf/index.html index d8ee3bba..3f18c8a9 100644 --- a/dev/tiny_httpd/Tiny_httpd_buf/index.html +++ b/dev/tiny_httpd/Tiny_httpd_buf/index.html @@ -1,2 +1,2 @@ -
Tiny_httpd_bufSimple buffer.
These buffers are used to avoid allocating too many byte arrays when processing streams and parsing requests.
val size : t -> intval clear : t -> unitval create : ?size:int -> unit -> tval contents : t -> stringval bytes_slice : t -> bytesAccess underlying slice of bytes.
val contents_and_clear : t -> stringGet contents of the buffer and clear it.
val add_bytes : t -> bytes -> int -> int -> unitAppend given bytes slice to the buffer.
val add_string : t -> string -> unitAdd string.
val add_buffer : t -> Stdlib.Buffer.t -> unitAppend bytes from buffer.
Tiny_httpd_bufSimple buffer.
These buffers are used to avoid allocating too many byte arrays when processing streams and parsing requests.
val size : t -> intval clear : t -> unitval create : ?size:int -> unit -> tval contents : t -> stringval bytes_slice : t -> bytesAccess underlying slice of bytes.
val contents_and_clear : t -> stringGet contents of the buffer and clear it.
val add_char : t -> char -> unitAdd a single char.
val add_bytes : t -> bytes -> int -> int -> unitAppend given bytes slice to the buffer.
val add_string : t -> string -> unitAdd string.
val add_buffer : t -> Stdlib.Buffer.t -> unitAppend bytes from buffer.
Tiny_httpd_htmlHTML combinators.
This module provides combinators to produce html. It doesn't enforce the well-formedness of the html, unlike Tyxml, but it's simple and should be reasonably efficient.
module Out = Tiny_httpd_html_.OutOutput for HTML combinators.
type elt = Out.t -> unitA html element. It is represented by its output function, so we can directly print it.
Element with children, represented as a list.
A chunk of sub-elements, possibly empty.
Element with children, represented as a list of sub_elt to be flattened
val sub_empty : sub_eltSub-element with nothing inside. Useful in conditionals, when one decides not to emit a sub-element at all.
val txt : string -> eltEmit a string value, which will be escaped.
val txtf :
+Tiny_httpd_html (tiny_httpd.Tiny_httpd_html) Module Tiny_httpd_html
HTML combinators.
This module provides combinators to produce html. It doesn't enforce the well-formedness of the html, unlike Tyxml, but it's simple and should be reasonably efficient.
module IO = Tiny_httpd_iomodule Out = Tiny_httpd_html_.OutOutput for HTML combinators.
type elt = Out.t -> unitA html element. It is represented by its output function, so we can directly print it.
Element with children, represented as a list.
A chunk of sub-elements, possibly empty.
Element with children, represented as a list of sub_elt to be flattened
val sub_empty : sub_eltSub-element with nothing inside. Useful in conditionals, when one decides not to emit a sub-element at all.
val txt : string -> eltEmit a string value, which will be escaped.
val txtf :
('a, Stdlib.Format.formatter, unit, Out.t -> unit) Stdlib.format4 ->
- 'bFormatted version of txt
val raw_html : string -> eltEmit raw HTML. Caution, this can lead to injection vulnerabilities, never use with text that comes from untrusted users.
tag "menuitem", see mdn
tag "footer", see mdn
tag "footer", see mdn
tag "menu", see mdn
tag "menu", see mdn
tag "nav", see mdn
tag "nav", see mdn
module A = Tiny_httpd_html_.AAttributes.
val to_string : ?top:bool -> elt -> stringConvert a HTML element to a string.
val to_string_l : elt list -> stringConvert a list of HTML elements to a string. This is designed for fragments of HTML that are to be injected inside a bigger context, as it's invalid to have multiple elements at the toplevel of a HTML document.
val to_string_top : elt -> stringval to_stream : elt -> Tiny_httpd_stream.tConvert a HTML element to a stream. This might just convert it to a string first, do not assume it to be more efficient.
\ No newline at end of file
+ 'bFormatted version of txt
val raw_html : string -> eltEmit raw HTML. Caution, this can lead to injection vulnerabilities, never use with text that comes from untrusted users.
tag "menuitem", see mdn
tag "footer", see mdn
tag "footer", see mdn
tag "menu", see mdn
tag "menu", see mdn
tag "nav", see mdn
tag "nav", see mdn
module A = Tiny_httpd_html_.AAttributes.
val to_out_channel : ?top:bool -> elt -> IO.Out_channel.t -> unitWrite an HTML element to this out channel.
val to_string : ?top:bool -> elt -> stringConvert a HTML element to a string.
val to_string_l : elt list -> stringConvert a list of HTML elements to a string. This is designed for fragments of HTML that are to be injected inside a bigger context, as it's invalid to have multiple elements at the toplevel of a HTML document.
val to_string_top : elt -> stringval to_out_channel_top : elt -> IO.Out_channel.t -> unitWrite a toplevel element to an output channel.
val to_writer : ?top:bool -> elt -> IO.Writer.tProduce a streaming writer from this HTML element.
val to_stream : elt -> Tiny_httpd_stream.tConvert a HTML element to a stream. This might just convert it to a string first, do not assume it to be more efficient.
Tiny_httpd_html_.OutOutput for HTML combinators.
This output type is used to produce a string reasonably efficiently from a tree of combinators.
val create : unit -> tval clear : t -> unitval add_char : t -> char -> unitval add_string : t -> string -> unitval add_format_nl : t -> unitval with_no_format_nl : t -> (unit -> 'a) -> 'aval to_string : t -> stringTiny_httpd_html_.OutOutput for HTML combinators.
This output type is used to produce a string reasonably efficiently from a tree of combinators.
NOTE: this is experimental and an unstable API.
val create_of_buffer : Stdlib.Buffer.t -> tval create_of_out : Tiny_httpd_io.Out_channel.t -> tval flush : t -> unitval add_char : t -> char -> unitval add_string : t -> string -> unitval add_format_nl : t -> unitval with_no_format_nl : t -> (unit -> 'a) -> 'aTiny_httpd_io.In_channelval of_in_channel : ?close_noerr:bool -> Stdlib.in_channel -> tval of_unix_fd : ?close_noerr:bool -> Unix.file_descr -> tval input : t -> bytes -> int -> int -> intval close : t -> unitTiny_httpd_io.In_channelInput channel (byte source)
type t = {input : bytes -> int -> int -> int;Read into the slice. Returns 0 only if the channel is closed.
close : unit -> unit;Close the input. Must be idempotent.
*)}An input channel, i.e an incoming stream of bytes.
This can be a string, an int_channel, an Unix.file_descr, a decompression wrapper around another input channel, etc.
val of_in_channel : ?close_noerr:bool -> Stdlib.in_channel -> tval of_unix_fd : ?close_noerr:bool -> Unix.file_descr -> tval input : t -> bytes -> int -> int -> intRead into the given slice.
val close : t -> unitClose the channel.
Tiny_httpd_io.Out_channelval of_out_channel : ?close_noerr:bool -> Stdlib.out_channel -> tval output : t -> bytes -> int -> int -> unitval output_string : t -> string -> unitval close : t -> unitval flush : t -> unitTiny_httpd_io.Out_channelOutput channel (byte sink)
type t = {output_char : char -> unit;Output a single char
*)output : bytes -> int -> int -> unit;Output slice
*)flush : unit -> unit;Flush underlying buffer
*)close : unit -> unit;Close the output. Must be idempotent.
*)}An output channel, ie. a place into which we can write bytes.
This can be a Buffer.t, an out_channel, a Unix.file_descr, etc.
val of_out_channel : ?close_noerr:bool -> Stdlib.out_channel -> tof_out_channel oc wraps the channel into a Out_channel.t.
val of_buffer : Stdlib.Buffer.t -> tof_buffer buf is an output channel that writes directly into buf. flush and close have no effect.
val output_char : t -> char -> unitOutput the buffer slice into this channel
val output : t -> bytes -> int -> int -> unitOutput the buffer slice into this channel
val output_string : t -> string -> unitval close : t -> unitClose the channel.
val flush : t -> unitFlush (ie. force write) any buffered bytes.
Tiny_httpd_io.TCP_serverA TCP server abstraction
type t = {endpoint : unit -> string * int;Endpoint we listen on. This can only be called from within serve.
active_connections : unit -> int;Number of connections currently active
*)running : unit -> bool;Is the server currently running?
*)stop : unit -> unit;Ask the server to stop. This might not take effect immediately.
*)}Running server.
type builder = {serve : after_init:(t -> unit) -> handle:conn_handler -> unit -> unit;Blocking call to listen for incoming connections and handle them. Uses the connection handler to handle individual client connections.
*)}A TCP server implementation.
Tiny_httpd_io.TCP_serverA TCP server abstraction.
type t = {endpoint : unit -> string * int;Endpoint we listen on. This can only be called from within serve.
active_connections : unit -> int;Number of connections currently active
*)running : unit -> bool;Is the server currently running?
*)stop : unit -> unit;Ask the server to stop. This might not take effect immediately, and is idempotent. After this server.running() must return false.
}A running TCP server.
This contains some functions that provide information about the running server, including whether it's active (as opposed to stopped), a function to stop it, and statistics about the number of connections.
type builder = {serve : after_init:(t -> unit) -> handle:conn_handler -> unit -> unit;Blocking call to listen for incoming connections and handle them. Uses the connection handler handle to handle individual client connections in individual threads/fibers/tasks.
}A TCP server builder implementation.
Calling builder.serve ~after_init ~handle () starts a new TCP server on an unspecified endpoint (most likely coming from the function returning this builder) and returns the running server.
Tiny_httpd_io.WriterA writer abstraction.
Writer.
A writer is a push-based stream of bytes. Give it an output channel and it will write the bytes in it.
This is useful for responses: an http endpoint can return a writer as its response's body, and output into it as if it were a regular out_channel, including controlling calls to flush.
val make : write:(Out_channel.t -> unit) -> unit -> tval write : Out_channel.t -> t -> unitWrite into the channel.
val empty : tEmpty writer, will output 0 bytes.
val of_string : string -> tA writer that just emits the bytes from the given string.
Tiny_httpd_ioIO abstraction.
We abstract IO so we can support classic unix blocking IOs with threads, and modern async IO with Eio.
NOTE: experimental.
module Buf = Tiny_httpd_bufmodule In_channel : sig ... endmodule Out_channel : sig ... endmodule TCP_server : sig ... endA TCP server abstraction
Tiny_httpd_ioIO abstraction.
We abstract IO so we can support classic unix blocking IOs with threads, and modern async IO with Eio.
NOTE: experimental.
module Buf = Tiny_httpd_bufmodule In_channel : sig ... endInput channel (byte source)
module Out_channel : sig ... endOutput channel (byte sink)
module Writer : sig ... endA writer abstraction.
module TCP_server : sig ... endA TCP server abstraction.
Tiny_httpd_server.ResponseBody of a response, either as a simple string, or a stream of bytes, or nothing (for server-sent events notably).
type t = private {code : Response_code.t;headers : Headers.t;Headers of the reply. Some will be set by Tiny_httpd automatically.
body : body;Body of the response. Can be empty.
*)}A response to send back to a client.
val set_code : Response_code.t -> t -> tSet the response code.
val make_raw : ?headers:Headers.t -> code:Response_code.t -> string -> tMake a response from its raw components, with a string body. Use "" to not send a body at all.
val make_raw_stream :
+Response (tiny_httpd.Tiny_httpd_server.Response) Module Tiny_httpd_server.Response
type body = [ | `String of string| `Stream of byte_stream| `Writer of Tiny_httpd_io.Writer.t| `Void
]Body of a response, either as a simple string, or a stream of bytes, or nothing (for server-sent events notably).
`String str replies with a body set to this string, and a known content-length.`Stream str replies with a body made from this string, using chunked encoding.`Void replies with no body.`Writer w replies with a body created by the writer w, using a chunked encoding. It is available since NEXT_RELEASE.
type t = private {code : Response_code.t;headers : Headers.t;(*Headers of the reply. Some will be set by Tiny_httpd automatically.
*)body : body;(*Body of the response. Can be empty.
*)
}A response to send back to a client.
val set_code : Response_code.t -> t -> tSet the response code.
val make_raw : ?headers:Headers.t -> code:Response_code.t -> string -> tMake a response from its raw components, with a string body. Use "" to not send a body at all.
val make_raw_stream :
?headers:Headers.t ->
code:Response_code.t ->
byte_stream ->
@@ -9,7 +9,10 @@
tmake r turns a result into a response.
make (Ok body) replies with 200 and the body.make (Error (code,msg)) replies with the given error code and message as body.
val make_string :
?headers:Headers.t ->
(string, Response_code.t * string) Stdlib.result ->
- tSame as make but with a string body.
val make_writer :
+ ?headers:Headers.t ->
+ (Tiny_httpd_io.Writer.t, Response_code.t * string) Stdlib.result ->
+ tSame as make but with a writer body.
val make_stream :
?headers:Headers.t ->
(byte_stream, Response_code.t * string) Stdlib.result ->
tSame as make but with a stream body.
val fail :
diff --git a/dev/tiny_httpd/Tiny_httpd_stream/index.html b/dev/tiny_httpd/Tiny_httpd_stream/index.html
index 5958d82e..ce448efe 100644
--- a/dev/tiny_httpd/Tiny_httpd_stream/index.html
+++ b/dev/tiny_httpd/Tiny_httpd_stream/index.html
@@ -6,7 +6,7 @@
Bytes.blit self.bs self.off buf offset len;
self.consume len;
);
- lenval close : t -> unitClose stream
val empty : tStream with 0 bytes inside
val of_input : ?buf_size:int -> Tiny_httpd_io.In_channel.t -> tMake a buffered stream from the given channel.
val of_chan : ?buf_size:int -> Stdlib.in_channel -> tMake a buffered stream from the given channel.
val of_chan_close_noerr : ?buf_size:int -> Stdlib.in_channel -> tSame as of_chan but the close method will never fail.
val of_fd : ?buf_size:int -> Unix.file_descr -> tMake a buffered stream from the given file descriptor.
val of_fd_close_noerr : ?buf_size:int -> Unix.file_descr -> tSame as of_fd but the close method will never fail.
val of_bytes : ?i:int -> ?len:int -> bytes -> tA stream that just returns the slice of bytes starting from i and of length len.
val of_string : string -> tval iter : (bytes -> int -> int -> unit) -> t -> unitIterate on the chunks of the stream
val to_chan : Stdlib.out_channel -> t -> unitWrite the stream to the channel.
val to_chan' : Tiny_httpd_io.Out_channel.t -> t -> unitWrite to the IO channel.
val close : t -> unitClose stream
val empty : tStream with 0 bytes inside
val of_input : ?buf_size:int -> Tiny_httpd_io.In_channel.t -> tMake a buffered stream from the given channel.
val of_chan : ?buf_size:int -> Stdlib.in_channel -> tMake a buffered stream from the given channel.
val of_chan_close_noerr : ?buf_size:int -> Stdlib.in_channel -> tSame as of_chan but the close method will never fail.
val of_fd : ?buf_size:int -> Unix.file_descr -> tMake a buffered stream from the given file descriptor.
val of_fd_close_noerr : ?buf_size:int -> Unix.file_descr -> tSame as of_fd but the close method will never fail.
val of_bytes : ?i:int -> ?len:int -> bytes -> tA stream that just returns the slice of bytes starting from i and of length len.
val of_string : string -> tval iter : (bytes -> int -> int -> unit) -> t -> unitIterate on the chunks of the stream
val to_chan : Stdlib.out_channel -> t -> unitWrite the stream to the channel.
val to_chan' : Tiny_httpd_io.Out_channel.t -> t -> unitWrite to the IO channel.
val to_writer : t -> Tiny_httpd_io.Writer.tTurn this stream into a writer.
val make :
?bs:bytes ->
?close:(t -> unit) ->
consume:(t -> int -> unit) ->
@@ -22,4 +22,8 @@
size:int ->
too_short:(int -> unit) ->
t ->
- tread_exactly ~size bs returns a new stream that reads exactly size bytes from bs, and then closes.
val output_chunked : Stdlib.out_channel -> t -> unitWrite the stream into the channel, using the chunked encoding.
val output_chunked' : Tiny_httpd_io.Out_channel.t -> t -> unitWrite the stream into the channel, using the chunked encoding.
\ No newline at end of file
+ tread_exactly ~size bs returns a new stream that reads exactly size bytes from bs, and then closes.
val output_chunked : ?buf:Tiny_httpd_buf.t -> Stdlib.out_channel -> t -> unitWrite the stream into the channel, using the chunked encoding.
val output_chunked' :
+ ?buf:Tiny_httpd_buf.t ->
+ Tiny_httpd_io.Out_channel.t ->
+ t ->
+ unitWrite the stream into the channel, using the chunked encoding.