123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121(* Ocsigen
* http://www.ocsigen.org
* Copyright (C) 2010 Vincent Balat
*
* 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.
*)openJs_of_ocamlopenEliom_libincludeEliom_cookies_base(* CCC The tables are indexed by the hostname, not the port appear.
there are no particular reason. If needed it is possible to add it *)letcookie_tables:(floatoption*string*bool)Ocsigen_cookie_map.Map_inner.tOcsigen_cookie_map.Map_path.tJstable.t=Jstable.create()(** [in_local_storage] implements cookie substitutes for iOS WKWebView *)letget_table?(in_local_storage=false)=function|None->Ocsigen_cookie_map.Map_path.empty|Somehost->ifin_local_storagethenlethost=Js.string(host^"/substitutes")inJs.Optdef.caseDom_html.window##.localStorage(fun()->Ocsigen_cookie_map.Map_path.empty)(funst->Js.Opt.casest##(getItemhost)(fun()->Ocsigen_cookie_map.Map_path.empty)(funv->Json.unsafe_inputv))elseJs.Optdef.get(Jstable.findcookie_tables(Js.stringhost))(fun()->Ocsigen_cookie_map.Map_path.empty)(** [in_local_storage] implements cookie substitutes for iOS WKWebView *)letset_table?(in_local_storage=false)hostt=matchhostwith|None->()|Somehost->ifin_local_storagethenlethost=Js.string(host^"/substitutes")inJs.Optdef.caseDom_html.window##.localStorage(fun()->())(funst->st##(setItemhost(Json.outputt)))elseJstable.addcookie_tables(Js.stringhost)tletnow()=letdate=new%jsJs.date_nowindate##getTime/.1000.(** [in_local_storage] implements cookie substitutes for iOS WKWebView *)letupdate_cookie_table?(in_local_storage=false)hostcookies=letnow=now()inOcsigen_cookie_map.Map_path.iter(funpathtable->Ocsigen_cookie_map.Map_inner.iter(funname->function|OSet(Someexp,_,_)whenexp<=now->set_table~in_local_storagehost(Ocsigen_cookie_map.Poly.remove~pathname(get_table~in_local_storagehost))|OUnset->set_table~in_local_storagehost(Ocsigen_cookie_map.Poly.remove~pathname(get_table~in_local_storagehost))|OSet(exp,value,secure)->set_table~in_local_storagehost(Ocsigen_cookie_map.Poly.add~pathname(exp,value,secure)(get_table~in_local_storagehost)))table)cookies(** [in_local_storage] implements cookie substitutes for iOS WKWebView *)letget_cookies_to_send?(in_local_storage=false)hosthttpspath=letnow=now()inOcsigen_cookie_map.Map_path.fold(funcpathtcookies_to_send->ifUrl.is_prefix_skip_end_slash(Url.remove_slash_at_beginningcpath)(Url.remove_slash_at_beginningpath)thenOcsigen_cookie_map.Map_inner.fold(funname(exp,value,secure)cookies_to_send->matchexpwith|Someexpwhenexp<=now->set_table~in_local_storagehost(Ocsigen_cookie_map.Poly.remove~path:cpathname(get_table~in_local_storagehost));cookies_to_send|_->if(notsecure)||httpsthen(name,value)::cookies_to_sendelsecookies_to_send)tcookies_to_sendelsecookies_to_send)(get_table~in_local_storagehost)[]letmake_new_session_id()=failwith"Cannot define anonymous coservices on client side. Ask their values to the server."