This commit is contained in:
parent
12d8e72514
commit
a70c79db96
1 changed files with 22 additions and 17 deletions
39
src/mte.ml
39
src/mte.ml
|
|
@ -15,27 +15,32 @@ type response = {
|
||||||
content: string;
|
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 =
|
let home_page_text =
|
||||||
"Hello!\n\nThis is MTE, the MirageOS Taler Exchange unikernel."
|
"Hello!\n\nThis is MTE, the MirageOS Taler Exchange unikernel."
|
||||||
|
|
||||||
let request_handler request =
|
let request_handler request =
|
||||||
match String.split_on_char '/' request.target with
|
match request_route request with
|
||||||
| [ ""; "" ] ->
|
| [ "" ] ->
|
||||||
let headers =
|
let content = home_page_text in
|
||||||
Headers.of_list
|
let headers = default_headers ~content `Text_plain in
|
||||||
[
|
{ status= `OK; headers; content }
|
||||||
("content-length", string_of_int (String.length home_page_text));
|
|
||||||
("connection", "close"); ("content-type", "text/plain");
|
|
||||||
]
|
|
||||||
in
|
|
||||||
{ status= `OK; headers; content= home_page_text }
|
|
||||||
| _ ->
|
| _ ->
|
||||||
let content = "Not found." in
|
let content = "Not found." in
|
||||||
let headers =
|
let headers = default_headers ~content `Text_plain in
|
||||||
Headers.of_list
|
|
||||||
[
|
|
||||||
("content-length", string_of_int (String.length content));
|
|
||||||
("connection", "close"); ("content-type", "text/plain");
|
|
||||||
]
|
|
||||||
in
|
|
||||||
{ status= `Not_found; headers; content }
|
{ status= `Not_found; headers; content }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue