module Opache:sig
..end
val params_of_query : string -> (string, string) Batteries.Hashtbl.t
val stripped : string -> string
val serve : Host.host_trx ->
Tcp.Port.t -> (Http.TRXtop.t -> Http.Pdu.t -> Log.logger -> 'a) -> unit
host
on given port
,
passing incoming messages to a user supplied function f
.
A simple server may be used like:
(* Server *)
let server = Host.make_static "server" (Eth.Addr.random ()) (Ip.Addr.of_string "192.168.1.1");;
let content_of file = File.lines_of file |> List.of_enum |> String.concat "";;
Opache.serve server (Tcp.Port.o 8080) (fun trx _msg _log ->
Http.TRXtop.tx trx (Http.Pdu.make_status 200 ["Content-Type", "text/plain"] (content_of "test.ml")));;
(* Our client *)
let client = Host.make_static "client" (Eth.Addr.random ()) (Ip.Addr.of_string "192.168.1.2");;
let browser = Browser.make client;;
(* Link with a tap in between *)
let tap = Hub.Tap.make (Pcap.save "http.pcap");;
client.Host.dev <--> tap.ins ; tap.out <--> server.Host.dev;;
(* Send a request *)
Browser.request browser ~headers:["Connection", "close"]
(Url.of_string "http://192.168.1.1:8080/") (function
| None -> Printf.printf "fail\n"
| Some (headers, body) ->
Printf.printf "\nResult:\n%a\n\n%s\n" Http.print_headers headers body);;
Clock.run false;;
Notice that this example, if copied into test.ml, will generate a pcap containing the source code that
generates the pcap :-)
multiplexer
.val print_vars : 'a BatInnerIO.output -> (string, string) Batteries.Hashtbl.t -> unit
exception ResourceError of int * string
val content_type_from_filename : string -> string
val static_file_server : string ->
'a -> string list -> 'b -> 'c -> 'd BatIO.output -> (string * string) list
val it_works : 'a ->
string list -> 'b -> 'c -> 'd BatInnerIO.output -> (string * string) list
typeparams =
(string, string) Batteries.Hashtbl.t
typeresource =
(Str.regexp *
(string ->
string list ->
params -> string -> string BatIO.output -> Http.header list))
list
val multiplexer : resource -> Http.TRXtop.t -> Http.Pdu.t -> Log.logger -> unit