Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*type statusCodes = OK | CREATED | ... ;;*)
- (* HTTP/1.1 200 OK *)
- type status = {version : string; code : int} ;;
- let string_of_status status = status.version ^ " " ^ string_of_int status.code ^ " " ^ match status.code with | 0 -> "GH" | 100 -> "Continue" | 101 -> "Switching Protocol" | 200 -> "OK" | 201 -> "CREATED" | 404 -> "NOT FOUND" | 418 -> "I AM A TEAPOT" | n -> "Unknown Status " ^ string_of_int n;;
- type field = | Server of string | ContentLength of int | ContentType of string
- let string_of_field f = match f with
- | Server name -> "Server :" ^ name
- | ContentLength length -> "ContentLength :" ^ string_of_int length
- | ContentType ct -> "Content-Type: " ^ ct;;
- let sI = string_of_int ;;
- type date = {day : int; day_of_month : int ; month : int; year : int ; hour : int ; minute : int ; second : int ; time_zone : string};;
- let string_of_date d = sI d.day ^ " " ^ sI d.day_of_month ^ " " ^ sI d.month ^ " " ^ sI d.year ^ " " ^ sI d.hour ^ " " ^ sI d.minute ^ " " ^ sI d.second ^ " " ^ d.time_zone ;;
- type response = {
- status : status;
- date : date;
- headers : field list;
- expires : date;
- body : string;
- }
- let mystatus = {version = "HTTP/1.1"; code = 200} ;;
- let myresponse = {
- status = mystatus;
- headers = [
- Server "nginx/1.6.2";
- ContentLength 12;
- ContentType "text/html; charset=utf-8";
- ];
- expires = {19;12;1978;5;0;0;"GMT"};
- body = "hello world!";
- }
- (*MAP function called to all members
- List.map string_of_int stevila ;;
- String.concat "" (List.map string_of_int stevila); *)
- let string_of_response r = string_of_status r.status ^ "\r\n" ^ String.concat "\r\n" (List.map string_of_field r.headers) ^ "\r\n" ^ string_of_date d.expires ^ "\r\n" ^ r.body ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement