This commit is contained in:
swrup 2025-11-05 21:56:16 +01:00
parent 12d8e72514
commit a70c79db96

View file

@ -15,27 +15,32 @@ type response = {
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 String.split_on_char '/' request.target with
| [ ""; "" ] ->
let headers =
Headers.of_list
[
("content-length", string_of_int (String.length home_page_text));
("connection", "close"); ("content-type", "text/plain");
]
in
{ status= `OK; headers; content= home_page_text }
match request_route request with
| [ "" ] ->
let content = home_page_text in
let headers = default_headers ~content `Text_plain in
{ status= `OK; headers; content }
| _ ->
let content = "Not found." in
let headers =
Headers.of_list
[
("content-length", string_of_int (String.length content));
("connection", "close"); ("content-type", "text/plain");
]
in
let headers = default_headers ~content `Text_plain in
{ status= `Not_found; headers; content }