Skip to content

Instantly share code, notes, and snippets.

@andreypopp andreypopp/cohttp_test.ml Secret
Created Oct 27, 2012

Embed
What would you like to do?
open Printf
open Lwt
open Cohttp
open Cohttp_lwt_unix
let make_server () =
let callback conn_id ?body req =
match Request.path req with
| "" | "/" ->
Server.respond_string ~status:`OK ~body:"helloworld" ()
| "/post" -> begin
lwt body = Body.string_of_body body in
Server.respond_string ~status:`OK ~body ()
end
| "/postnodrain" ->
Server.respond_string ~status:`OK ~body:"nodrain" ()
| _ ->
let fname = Server.resolve_file ~docroot:"." ~uri:(Request.uri req) in
Server.respond_file ~fname ()
in
let conn_closed conn_id () =
Printf.eprintf "conn %s closed\n%!" (Server.string_of_conn_id conn_id)
in
let config = { Server.callback; conn_closed } in
server ~address:"0.0.0.0" ~port:8081 config
let _ = Lwt_unix.run (make_server ())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.