This module mainly defines the
http_protocol class which implements the
exchange of messages with a HTTP client. The request messages are represented
as sequence of
req_token values. The response is encapsulated in a separate
http_response class. The contents of the response are represented as sequence
| `TLS_error of string * string
| `Unix_error of Unix.error ]
`Timeout refers to a timeout in the middle of a request.
`Broken_pipe_ignore is the "harmless" version of
Long messages are fatal because it is suspected that they are denial
of service attacks. The kernel generates
`Message_too_long only for
long headers, not for long bodies.
Fatal server errors can happen when exceptions are not properly handled. As last resort the HTTP daemon closes the connection without notifying the client.
`TLS_error means any error on the TLS level. The two strings identify
the problem as for
val string_of_fatal_error :
fatal_error -> string
| `Bad_header_field of string
| `Format_error of string
| `Unexpected_eof ]
val string_of_bad_request_error :
bad_request_error -> string
val status_of_bad_request_error :
bad_request_error -> Nethttp.http_status
string * int * int
data_chunkis a substring of a string. The substring is described by the triple
(s, pos, len)where
sis the container,
posis the position where the substring begins, and
int * string
[ `Chunked | `Identity ]
[ `Resp_action of unit -> unit
| `Resp_body of data_chunk
| `Resp_header of Nethttp.http_header
| `Resp_info_line of status_line * Nethttp.http_header
| `Resp_status_line of status_line
| `Resp_trailer of Nethttp.http_trailer ]
resp_tokenrepresents a textual part of the response to send:
`Resp_info_lineis an informational status line (code=100..199). There can be several informational lines, and they can be accompanied with their own headers. Such lines are only sent to HTTP/1.1 clients.
`Resp_status_lineis the final status line to send (code >= 200)
`Resp_headeris the whole response header to send
`Resp_bodyis the next part of the response body to send.
`Resp_traileris the whole response trailer to send (currently ignored)
`Resp_actionis special because it does not directly represent a token to send. The argument is a function which is called when the token is the next token on the active event queue. The function is also called when the event queue is dropped because of an error (the state of the response object indicates this). The function must not raise exceptions except
Unix_error, and it must not block.
val resp_100_continue :
[ `Active | `Dropped | `Error | `Inhibited | `Processed | `Queued ]
`Inhibited= it is not yet allowed to start the response
`Queued= the response waits on the queue for activation
`Active= the response is currently being transmitted
`Processed= the response has been completely sent
`Error= an error occurred during the transmission of this response
`Dropped= an earlier response forced to close the connection, and this response is dequeued
[ `Resp_end | `Resp_wire_data of data_chunk ]
`Resp_wire_dataare data tokens.
`Resp_endindicates the end of the response.
[ `As of string | `Ignore | `Ocamlnet | `Ocamlnet_and of string ]
class type http_response =
class http_response_impl :
?close:bool -> ?suppress_body:bool -> int64 -> Nethttp.protocol -> announcement ->
val send_static_response :
Nethttp.http_status -> Nethttp.http_header option -> string -> unit
Content-Lengthis set to the length of the string.
Content-Typeis set to "text/html" unless given by the header. If the header object is passed in, these modifications are done directly in this object as side effect.
val send_file_response :
Nethttp.http_header option -> Unix.file_descr -> int64 -> unit
Content-Lengthis set to the length of the string.
Content-Typeis set to "text/html" unless given by the header.
Content-Rangeis not set automatically, even if the file is only partially transferred.
If the header object is passed in, these modifications are done directly in this object as side effect.
The function does not send the file immediately, but rather sets the
object up that the next chunk of the file is added when the send queue becomes
empty. This file will be closed when the transfer is done.
Nethttp.http_method * Nethttp.protocol
[ `Bad_request_error of
bad_request_error * http_response
| `Fatal_error of fatal_error
| `Req_body of data_chunk
| `Req_header of
request_line * Nethttp.http_header *
| `Req_trailer of Nethttp.http_trailer
| `Timeout ]
req_tokenrepresents a textual part of the received request:
`Req_headeris the full received header. Together with the header, the corresponding
http_responseobject is returned which must be used to transmit the response.
`Req_expect_100_continueis generated when the client expects that the server sends a "100 Continue" response (or a final status code) now. One should add
`Resp_info_line resp_100_continueto the send queue if the header is acceptable, or otherwise generate an error response. In any case, the rest of the request must be read until
`Req_bodyis a part of the request body. The transfer-coding, if any, is already decoded.
`Req_traileris the received trailer
`Req_endindicates the end of the request (the next request may begin immediately).
`Eofindicates the end of the stream
`Bad_request_errorindicates that the request violated the HTTP protocol in a serious way and cannot be decoded. It is required to send a "400 Bad Request" response. The following token will be
`Fatal_errorindicates that the connection crashed. The following token will be
`Timeoutmeans that nothing has been received for a certain amount of time, and the protocol is in a state that the next request can begin. The following token will be
sendtokens to the client. The protocol implementation takes care that the response is transmitted at the right point in time.
val string_of_req_token :
req_token -> string
class type http_protocol_config =
val default_http_protocol_config :
config_max_reqline_length = 32768
config_max_header_length = 65536
config_max_trailer_length = 32768
config_limit_pipeline_length = 5
config_limit_pipeline_size = 65536
config_announce_server = `Ocamlnet
config_suppress_broken_pipe = false
config_tls = None
class modify_http_protocol_config :
?config_max_reqline_length:int -> ?config_max_header_length:int -> ?config_max_trailer_length:int -> ?config_limit_pipeline_length:int -> ?config_limit_pipeline_size:int -> ?config_announce_server:announcement -> ?config_suppress_broken_pipe:bool -> ?config_tls:Netsys_crypto_types.tls_config option -> http_protocol_config ->
class type http_protocol_hooks =
class http_protocol :
#http_protocol_config -> Unix.file_descr ->
class lingering_close :
?preclose:unit -> unit -> Unix.file_descr ->