Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file httpev_common.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196openPrintftypeencoding=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;}typestatus_code=[`Ok|`Created|`Accepted|`No_content|`Found|`Moved|`Permanent_redirect|`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]typereply_status=[status_code|`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")letpairs_of_requestreq:Logger.Pairs.t=["req_id",string_of_intreq.id;"client_addr",show_client_addrreq;"http_duration",sprintf"%.4f"(Time.get()-.req.conn);"http_recv_duration",sprintf"%.4f"(req.recv-.req.conn);"http_host",header_safereq"host";"url",req.url;"http_user_agent",header_safereq"user-agent";"http_req_id",header_safereq"x-request-id"]letstatus_code:reply_status->int=function|`Ok->200|`Created->201|`Accepted->202|`No_content->204|`Moved->301|`Found->302|`Permanent_redirect->308|`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_version=function|`Http_1_0->"HTTP/1.0"|`Http_1_1->"HTTP/1.1"letshow_status_code:status_code->string=function|`Ok->"200 OK"|`Created->"201 Created"|`Accepted->"202 Accepted"|`No_content->"204 No Content"|`Moved->"301 Moved Permanently"|`Found->"302 Found"|`Permanent_redirect->"308 Permanent Redirect"|`Bad_request->"400 Bad Request"|`Unauthorized->"401 Unauthorized"|`Payment_required->"402 Payment Required"|`Forbidden->"403 Forbidden"|`Not_found->"404 Not Found"|`Method_not_allowed->"405 Method Not Allowed"|`Not_acceptable->"406 Not Acceptable"|`Conflict->"409 Conflict"|`Length_required->"411 Length Required"|`Request_too_large->"413 Request Entity Too Large"|`I'm_a_teapot->"418 I'm a teapot"|`Unprocessable_content->"422 Unprocessable Content"|`Too_many_requests->"429 Too Many Requests"|`Internal_server_error->"500 Internal Server Error"|`Not_implemented->"501 Not Implemented"|`Service_unavailable->"503 Service Unavailable"|`Version_not_supported->"505 HTTP Version Not Supported"letshow_http_reply:version:[`Http_1_0|`Http_1_1]->reply_status->string=fun~versionreply_status->matchreply_statuswith|`Customs->s|#status_codeascode->sprintf"%s %s"(show_http_versionversion)(show_status_codecode)(* 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";],"")