Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file media_type.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (C) 2016, OCamlPro. *)(* Copyright (c) 2020-2021 Nomadic Labs <contact@nomadic-labs.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)moduleMake(Encoding:Resto.ENCODING)=structopenCohttptypet={name:Cohttp.Accept.media_range;q:intoption;pp:'a.'aEncoding.t->Format.formatter->string->unit;construct:'a.'aEncoding.t->'a->string;construct_seq:'a.'aEncoding.t->'a->(Bytes.t*int*int)Seq.t;destruct:'a.'aEncoding.t->string->('a,string)result;}letname_of_media_type=function|Accept.AnyMedia->"*/*"|AnyMediaSubtypetype_->type_^"/*"|MediaType(type_,subtype)->type_^"/"^subtypeletname{name;_}=name_of_media_typenameletrechas_complete_media=function|[]->false|{name=MediaType_;_}::_->true|_::l->has_complete_medialletrecfirst_complete_media=function|[]->None|({name=MediaType(l,r);_}asm)::_->Some((l,r),m)|_::l->first_complete_medialletmatching_media(type_,subtype)=function|Accept.AnyMedia->true|AnyMediaSubtypetype_'->type_'=type_|MediaType(type_',subtype')->type_'=type_&&subtype'=subtypeletrecfind_mediareceived=function|[]->None|({name;_}asmedia)::_whenmatching_mediareceivedname->Somemedia|_::mts->find_mediareceivedmts(* Inspired from ocaml-webmachine *)letmedia_match(_,(range,_))media=matchmedia.namewith|AnyMedia|AnyMediaSubtype_->false|MediaType(type_,subtype)->(letopenAcceptinmatchrangewith|AnyMedia->true|AnyMediaSubtypetype_'->type_'=type_|MediaType(type_',subtype')->type_'=type_&&subtype'=subtype)letresolve_accept_headerprovidedheader=letranges=Accept.(media_rangesheader|>qsort)inletrecloop=function|[]->None|r::rs->(tryletmedia=List.find(media_matchr)providedinSome(name_of_media_typemedia.name,media)withNot_found->looprs)inlooprangesletaccept_headerranges=letranges=List.map(funr->letq=matchr.qwithNone->1000|Somei->iin(q,(r.name,[])))rangesinAccept.string_of_media_rangesrangesletacceptable_encodingranges=String.concat", "(List.map(funf->name_of_media_typef.name)ranges)end