Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file httpev_common.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174openPrintftypeencoding=Gzip|Identitytypemeth=[|`GET|`POST|`PUT|`PATCH|`DELETE|`HEAD|`OPTIONS]typerequest={addr:Unix.sockaddr;url:string;(* path and arguments *)path:string;args:(string*string)list;conn:Time.t;(* time when client connected *)recv:Time.t;(* time when client request was fully read *)meth:meth;headers:(string*string)list;body:string;version:int*int;(* client HTTP version *)id:int;(* request id *)socket:Unix.file_descr;line:string;(** request line *)mutableblocking:unitIO.outputoption;(* hack for forked childs *)encoding:encoding;}typereply_status=[`Ok|`Created|`Accepted|`No_content|`Found|`Moved|`Bad_request|`Unauthorized|`Payment_required|`Forbidden|`Not_found|`Method_not_allowed|`Not_acceptable|`Conflict|`Length_required|`Request_too_large|`I'm_a_teapot|`Unprocessable_content|`Too_many_requests|`Internal_server_error|`Not_implemented|`Service_unavailable|`Version_not_supported|`Customofstring]typeextended_reply_status=[reply_status|`No_reply]type'statusreply'='status*(string*string)list*stringtypereply=extended_reply_statusreply'letshow_method=function|`GET->"GET"|`POST->"POST"|`PUT->"PUT"|`PATCH->"PATCH"|`DELETE->"DELETE"|`HEAD->"HEAD"|`OPTIONS->"OPTIONS"letmethod_of_string=function|"GET"->`GET|"POST"->`POST|"PUT"->`PUT|"PATCH"->`PATCH|"DELETE"->`DELETE|"HEAD"->`HEAD|"OPTIONS"->`OPTIONS|s->Exn.fail"method_of_string %s"sletshow_client_addr?(via=[Unix.inet_addr_loopback])req=letheader_ordefault=tryList.assoc"x-real-ip"req.headerswithNot_found->defaultinmatchreq.addrwith|Unix.ADDR_UNIX_->header_or@@Nix.show_addrreq.addr|ADDR_INET(addr,_)whenList.memaddrvia->header_or@@Unix.string_of_inet_addraddr|ADDR_INET(addr,_)->Unix.string_of_inet_addraddrletclient_addrreq=matchreq.addrwithUnix.ADDR_INET(addr,port)->addr,port|_->assertfalseletclient_ipreq=fst@@client_addrreqletfind_headerreqname=List.assoc(String.lowercase_asciiname)req.headersletheader_exnreqname=tryfind_headerreqnamewith_->Exn.fail"header %S"nameletheader_safereqname=tryfind_headerreqnamewith_->""letheader_refererreq=tryfind_headerreq"Referer"with_->tryfind_headerreq"Referrer"with_->""letshow_requestreq=sprintf"#%d %s time %.4f (recv %.4f) %s %s%s %S %S"req.id(show_client_addrreq)(Time.get()-.req.conn)(req.recv-.req.conn)(show_methodreq.meth)(header_safereq"host")req.url(header_safereq"user-agent")(header_safereq"x-request-id")letstatus_code:reply_status->int=function|`Ok->200|`Created->201|`Accepted->202|`No_content->204|`Moved->301|`Found->302|`Bad_request->400|`Unauthorized->401|`Payment_required->402|`Forbidden->403|`Not_found->404|`Method_not_allowed->405|`Not_acceptable->406|`Conflict->409|`Length_required->411|`Request_too_large->413|`I'm_a_teapot->418|`Unprocessable_content->422|`Too_many_requests->429|`Internal_server_error->500|`Not_implemented->501|`Service_unavailable->503|`Version_not_supported->505|`Custom_->999letshow_http_reply:reply_status->string=function|`Ok->"HTTP/1.0 200 OK"|`Created->"HTTP/1.0 201 Created"|`Accepted->"HTTP/1.0 202 Accepted"|`No_content->"HTTP/1.0 204 No Content"|`Moved->"HTTP/1.0 301 Moved Permanently"|`Found->"HTTP/1.0 302 Found"|`Bad_request->"HTTP/1.0 400 Bad Request"|`Unauthorized->"HTTP/1.0 401 Unauthorized"|`Payment_required->"HTTP/1.0 402 Payment Required"|`Forbidden->"HTTP/1.0 403 Forbidden"|`Not_found->"HTTP/1.0 404 Not Found"|`Method_not_allowed->"HTTP/1.0 405 Method Not Allowed"|`Not_acceptable->"HTTP/1.0 406 Not Acceptable"|`Conflict->"HTTP/1.0 409 Conflict"|`Length_required->"HTTP/1.0 411 Length Required"|`Request_too_large->"HTTP/1.0 413 Request Entity Too Large"|`I'm_a_teapot->"HTTP/1.0 418 I'm a teapot"|`Unprocessable_content->"HTTP/1.0 422 Unprocessable Content"|`Too_many_requests->"HTTP/1.0 429 Too Many Requests"|`Internal_server_error->"HTTP/1.0 500 Internal Server Error"|`Not_implemented->"HTTP/1.0 501 Not Implemented"|`Service_unavailable->"HTTP/1.0 503 Service Unavailable"|`Version_not_supported->"HTTP/1.0 505 HTTP Version Not Supported"|`Customs->s(* basically allow all *)letcors_preflight_allow_all=(`No_content,["Access-Control-Allow-Origin","*";"Access-Control-Allow-Methods","GET, POST, OPTIONS, PUT, PATCH, DELETE, HEAD";"Access-Control-Max-Age","600";],"")