Warning: Reason support is experimental. We are looking for beta-tester and contributors.

Module Ocsigen_http_com

module Ocsigen_http_com : sig..end

Sending and receiving HTTP frames


exception Connection_closed

The other side has cleanly closed the connection after a message

exception Lost_connection of exn

The connection has been unexpectedly broken

exception Timeout

No activity on the other side

exception Keepalive_timeout
exception Aborted

Connection killed

type mode =  | Answer | Query | Nofirstline
type connection
val create_receiver : 
  int ->
  mode -> Lwt_ssl.socket -> connection
val lock_receiver : connection -> unit Lwt.t
val unlock_receiver : connection -> unit
val wakeup_next_request : connection -> unit
val block_next_request : connection -> unit Lwt.t
val get_http_frame : 
  ?head:bool ->
  connection -> Ocsigen_http_frame.t Lwt.t
val connection_id : connection -> int
val connection_fd : connection -> Lwt_ssl.socket
val closed : connection -> unit Lwt.t

closed conn is a thread waking up when the connection is closed

type slot
val start_processing : 
  connection ->
  (slot -> unit Lwt.t) -> unit
val wait_all_senders : connection -> unit Lwt.t
val write_stream : 
  ?chunked:bool ->
  Lwt_chan.out_channel -> string Ocsigen_stream.t -> unit Lwt.t

This function may return any I/O error from the channel, or a interrupted stream exception.

type sender_type
val create_sender : 
  ?server_name:string ->
  ?headers:Http_headers.t ->
  ?proto:Ocsigen_http_frame.Http_header.proto ->
  unit -> sender_type
val default_sender : sender_type

Sender with only the server name, and HTTP/1.1

val send : 
  ?reopen:(unit -> unit Lwt.t) ->
  slot ->
  clientproto:Ocsigen_http_frame.Http_header.proto ->
  ?mode:Ocsigen_http_frame.Http_header.http_mode ->
  ?proto:Ocsigen_http_frame.Http_header.proto ->
  ?keep_alive:bool ->
  head:bool ->
  sender:sender_type ->
  Ocsigen_http_frame.result -> unit Lwt.t

send an HTTP message. send may also fail with Interrupted_stream exception if the input stream is interrupted.

val abort : connection -> unit
val set_result_observer : 
  (Ocsigen_http_frame.Http_header.http_header -> string -> unit Lwt.t) ->
  unit

Use this function to make an action just before sending the result (for example observe the headers that will be sent). The parameter is a function taking the set of headers twice, first as Ocsigen_http_frame.Http_headers.http_header, second as a string.