123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197(* Ocsigen
* http://www.ocsigen.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, with linking exception;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)typet=Cohttp.Header.tletof_option=functionSomeh->h|None->Cohttp.Header.init()moduleName=structtypet=stringletof_string=String.lowercase_asciiletto_strings=sletaccept=of_string"Accept"letaccept_charset=of_string"Accept-Charset"letaccept_encoding=of_string"Accept-Encoding"letaccept_language=of_string"Accept-Language"letaccept_ranges=of_string"Accept-Ranges"letauthorization=of_string"Authorization"letcache_control=of_string"Cache-Control"letconnection=of_string"Connection"letcontent_disposition=of_string"Content-Disposition"letcontent_encoding=of_string"Content-Encoding"letcontent_range=of_string"Content-Range"letcontent_length=of_string"Content-Length"letcontent_type=of_string"Content-Type"letcookie=of_string"Cookie"letdate=of_string"Date"letetag=of_string"ETag"letexpect=of_string"Expect"letexpires=of_string"Expires"lethost=of_string"Host"letif_match=of_string"If-Match"letif_modified_since=of_string"If-Modified-Since"letif_none_match=of_string"If-None-Match"letif_unmodified_since=of_string"If-Unmodified-Since"letif_range=of_string"If-Range"letlast_modified=of_string"Last-Modified"letlocation=of_string"Location"letpragma=of_string"Pragma"letserver=of_string"Server"letset_cookie=of_string"Set-Cookie"letstatus=of_string"Status"lettransfer_encoding=of_string"Transfer-Encoding"letuser_agent=of_string"User-Agent"letreferer=of_string"Referer"letrange=of_string"Range"letx_forwarded_for=of_string"X-Forwarded-For"letx_forwarded_proto=of_string"X-Forwarded-Proto"(* CORS headers *)letorigin=of_string"Origin"letaccess_control_request_method=of_string"Access-Control-Request-Method"letaccess_control_request_headers=of_string"Access-Control-Request-Headers"letaccess_control_allow_origin=of_string"Access-Control-Allow-Origin"letaccess_control_allow_credentials=of_string"Access-Control-Allow-Credentials"letaccess_control_expose_headers=of_string"Access-Control-Expose-Headers"letaccess_control_max_age=of_string"Access-Control-Max-Age"letaccess_control_allow_methods=of_string"Access-Control-Allow-Methods"letaccess_control_allow_headers=of_string"Access-Control-Allow-Headers"endletparse_stara=ifa="*"thenNoneelseSomealetparse_qualityfs=tryleta,b=Ocsigen_lib.String.sep';'sinletq,qv=Ocsigen_lib.String.sep'='binifq="q"thenfa,Some(float_of_stringqv)elsefailwith"Parse error"with_->fs,NonemoduleMime_type=structtypet=stringoption*stringoptionletparsea=letb,c=Ocsigen_lib.String.sep'/'ainparse_starb,parse_starcendmoduleAccept=structtypet=(Mime_type.t*floatoption*(string*string)list)listletparse_extensionsparse_names=tryleta,b=Ocsigen_lib.String.sep';'sinparse_namea,List.map(Ocsigen_lib.String.sep'=')(Ocsigen_lib.String.split';'b)with_->parse_names,[]letparse_list_with_extensionsparse_names=List.map(Ocsigen_lib.String.split',')s|>List.flatten|>List.map(parse_extensionsparse_name)letparses=tryletl=parse_list_with_extensionsMime_type.parsesinletchange_quality(a,l)=tryletq,ll=Ocsigen_lib.List.assoc_remove"q"lina,Some(float_of_stringq),llwith_->a,None,linList.mapchange_qualitylwith_->[]endmoduleAccept_encoding=structtypet=(stringoption*floatoption)listletparses=tryList.map(Ocsigen_lib.String.split',')s|>List.flatten|>List.map(parse_qualityparse_star)with_->[]endmoduleAccept_language=structtypet=(string*floatoption)listletparses=tryList.map(Ocsigen_lib.String.split',')s|>List.flatten|>List.map(parse_quality(funx->x))with_->[]endmoduleContent_type=structletchooseacceptdefaultalt=tryList.find(funcontent_type->letf=function|(Somea,Someb),_,_->a^"/"^b=content_type|_->falseinList.existsfaccept)(default::alt)withNot_found->defaultend