Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file media_type.ml
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586(**************************************************************************)(* resto *)(* Copyright (C) 2016, OCamlPro. *)(* *)(* All rights reserved. This file is distributed under the terms *)(* of the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)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;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'=subtypeletresolve_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->looprsinlooprangesletaccept_headerranges=letranges=List.map(funr->letq=matchr.qwithNone->1000|Somei->iin(q,(r.name,[])))rangesin(Accept.string_of_media_rangesranges)letacceptable_encodingranges=String.concat", "(List.map(funf->name_of_media_typef.name)ranges)end