module Method = H2.Method module Headers = H2.Headers module Status = H2.Status type request = { meth: Method.t; target: string; scheme: string; headers: Headers.t; } type response = { status: Status.t; headers: Headers.t; content: string; } let request_route request = match String.split_on_char '/' request.target with | "" :: l -> l | _ -> assert false let content_type_to_string = function | `Text_plain -> "text/plain" | `Application_json -> "application/json" let default_headers ~content typ = Headers.of_list [ ("content-length", string_of_int (String.length content)); ("connection", "close"); ("content-type", content_type_to_string typ); ] let home_page_text = "Hello!\n\nThis is MTE, the MirageOS Taler Exchange unikernel." let request_handler request = match request_route request with | [ "" ] -> let content = home_page_text in let headers = default_headers ~content `Text_plain in Lwt.return { status= `OK; headers; content } | _ -> let content = "Not found." in let headers = default_headers ~content `Text_plain in Lwt.return { status= `Not_found; headers; content }