Skip to content

Instantly share code, notes, and snippets.

@andreypopp
Created October 27, 2012 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreypopp/8568c29b3addf98a4a70 to your computer and use it in GitHub Desktop.
Save andreypopp/8568c29b3addf98a4a70 to your computer and use it in GitHub Desktop.
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