123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229# 1 "src/lib/eliom_request_info.client.ml"(* Ocsigen
* http://www.ocsigen.org
* Module eliom_sessions.ml
* Copyright (C) 2009 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.
*)(* TODO: add missing functions to get
(almost) the same interface as server side *)(* - Part of sp is reconstructed client side
- Another part is sent as application parameter (sitedata)
- Antother part is sent with each request
*)openJs_of_ocamlopenEliom_libincludeEliom_typesletclient_app_initialised=reffalsetypet={path:stringlist;si:Eliom_common.sess_info}letdefault_ri=refNoneletri_key=Lwt.new_key()letget_ri()=matchLwt.getri_keywith|Somep->p|None->(match!default_riwith|Somep->p|None->failwith"Eliom_request_info.get_sess_info called before initialization")letget_sess_info()=(get_ri()).siletset_session_info~urisif=letpath=Url.path_of_url_string(ifuri="./"then""elseuri)inletri=Some{path;si}indefault_ri:=ri;Lwt.with_valueri_keyrifletmatches_regexpnamere=trylet_=Re.execrenameintruewithNot_found->falseletmatches_regexpsregexps(name,_)=List.exists(matches_regexpname)regexpsletupdate_session_info~path~all_get_params~all_post_paramscont=letignored_get,all_get_params=List.partition(matches_regexps!Eliom_process.ignored_get_params)all_get_paramsinletignored_post,all_post_params=matchall_post_paramswith|None->[],None|Somep->List.partition(matches_regexps!Eliom_process.ignored_post_params)p|>fun(a,b)->a,Somebinletnl_get_params,all_get_but_nl=Eliom_common.split_nl_prefix_paramall_get_paramsinletall_get_but_na_nl=lazy(Eliom_common.remove_na_prefix_paramsall_get_but_nl)andna_get_params=lazy(Eliom_common.filter_na_get_paramsall_get_but_nl)inlet{si;_}=get_ri()inletsi={siwithEliom_common.si_other_get_params=[];si_all_get_params=all_get_params;si_na_get_params=na_get_params;si_nl_get_params=nl_get_params;si_nl_post_params=Eliom_lib.String.Table.empty;si_all_post_params=all_post_params;si_all_get_but_nl=all_get_but_nl;si_all_get_but_na_nl=all_get_but_na_nl;si_ignored_get_params=ignored_get;si_ignored_post_params=ignored_post}inletri=Some{path;si}indefault_ri:=ri;Lwt.with_valueri_keyricontletremove_first_slashpath=matchpathwith""::l->l|l->lletget_original_full_path_sp_sp=(* returns current path, not the one when application started *)ifnot(Eliom_process.history_api||!client_app_initialised)thenmatchUrl.Current.get()with|Some(Url.Httpurl)|Some(Url.Httpsurl)->url.Url.hu_path|Some(Url.Fileurl)->(matchurl.Url.fu_pathwith""::l->l|l->l)|None->assertfalseelse(get_ri()).pathletget_original_full_path_string()=String.concat"/"(get_original_full_path_spsp)letget_original_full_path_string_sp=get_original_full_path_stringletget_nl_get_params()=(get_sess_info()).Eliom_common.si_nl_get_paramsletget_nl_get_params_sp=get_nl_get_paramsletget_persistent_nl_get_params()=Lazy.force(get_sess_info()).Eliom_common.si_persistent_nl_get_paramsletget_persistent_nl_get_params_sp=get_persistent_nl_get_paramsletget_si()=get_sess_info()letget_site_dir()=(Eliom_process.get_sitedata()).site_dirletget_site_dir_option()=Some(get_site_dir())letssl_=matchUrl.Current.get()with|Some(Url.Https_)->true|Some(Url.Http_)|Some(Url.File_)|None->falseletget_csp_ssl()=if!client_app_initialisedthen(Eliom_process.get_info()).Eliom_common.cpi_sslelsessl_letget_csp_ssl_sp=get_csp_ssllethost_=Url.Current.hostletget_csp_hostname()=if!client_app_initialisedthen(Eliom_process.get_info()).Eliom_common.cpi_hostnameelsehost_letget_csp_hostname_sp=get_csp_hostnameletport_=matchUrl.Current.portwithSomep->p|None->ifssl_then443else80letget_csp_server_port()=if!client_app_initialisedthen(Eliom_process.get_info()).Eliom_common.cpi_server_portelseport_letget_csp_server_port_sp=get_csp_server_portletget_csp_original_full_path()=if!client_app_initialised||Eliom_process.history_apithen(Eliom_process.get_info()).Eliom_common.cpi_original_full_pathelseremove_first_slashUrl.Current.pathletget_csp_original_full_path_sp=get_csp_original_full_pathletget_request_cookies=Eliom_process.get_request_cookiesletget_request_template=Eliom_process.get_request_template(* The request data used when it is not sent by server
(i.e. when the client side process is initiated by client (mobile app...)) *)letdefault_request_data={Eliom_common.ejs_global_data=None;ejs_request_data=[||];ejs_event_handler_table=Eliom_runtime.RawXML.ClosureMap.empty;ejs_client_attrib_table=Eliom_runtime.RawXML.ClosureMap.empty;ejs_sess_info={Eliom_common.si_other_get_params=[];si_all_get_params=[];si_all_post_params=None;si_all_file_params=None;si_service_session_cookies=Eliom_common.Full_state_name_table.empty;si_data_session_cookies=Eliom_common.Full_state_name_table.empty;si_persistent_session_cookies=Eliom_common.Full_state_name_table.empty;si_secure_cookie_info=(Eliom_common.Full_state_name_table.empty,Eliom_common.Full_state_name_table.empty,Eliom_common.Full_state_name_table.empty);si_service_session_cookies_tab=Eliom_common.Full_state_name_table.empty;si_data_session_cookies_tab=Eliom_common.Full_state_name_table.empty;si_persistent_session_cookies_tab=Eliom_common.Full_state_name_table.empty;si_secure_cookie_info_tab=(Eliom_common.Full_state_name_table.empty,Eliom_common.Full_state_name_table.empty,Eliom_common.Full_state_name_table.empty);si_tab_cookies=Ocsigen_cookie_map.Map_inner.empty;si_nonatt_info=Eliom_common.RNa_no;si_state_info=Eliom_common.RAtt_no,Eliom_common.RAtt_no;si_previous_extension_error=404;si_na_get_params=lazy[];si_nl_get_params=Eliom_lib.String.Table.empty;si_nl_post_params=Eliom_lib.String.Table.empty;si_nl_file_params=Eliom_lib.String.Table.empty;si_persistent_nl_get_params=lazyString.Table.empty;si_all_get_but_na_nl=lazy[];si_all_get_but_nl=[];si_ignored_get_params=[];si_ignored_post_params=[];si_client_process_info=None;si_expect_process_data=lazyfalse}}letget_request_data()=leteliom_request_data=Js.Unsafe.global##.___eliom_request_data_inJs.Optdef.caseeliom_request_data(fun()->default_request_data)(funvar->Eliom_unwrap.unwrap_jsvar)exceptionEliom_no_raw_post_data_on_clientletraw_post_data_=Lwt.failEliom_no_raw_post_data_on_clienttyperaw_post_data=unitletget_ignored_get_params()=(get_sess_info()).si_ignored_get_paramsletget_ignored_post_params()=(get_sess_info()).si_ignored_post_params