diff --git a/calexium_lib/web/CXM_cookies.anubis b/calexium_lib/web/CXM_cookies.anubis index 5393c78..b2da482 100644 --- a/calexium_lib/web/CXM_cookies.anubis +++ b/calexium_lib/web/CXM_cookies.anubis @@ -474,8 +474,8 @@ define List(Cookie) ) = if read_cookie is { - failure then so_far, - success(c) then read_cookies([c . so_far]) + failure then so_far, + success(c) then read_cookies([c . so_far]) }. @@ -508,8 +508,36 @@ public define List(Cookie) [h . t] then append(get_cookies(server_name,h),get_cookies(server_name,t)) }. + +define List(Cookie) + server_get_cookies + ( + HTTP_header h + ) = + if h is http_header(n,v) then + if to_lower(n) = "cookie" + then ( + unput_atoms <- []; + input <- v; + index <- 0; + server_name <- ""; + read_cookies([]) + ) + else []. - +public define List(Cookie) + server_get_cookies + ( + // String server_name, + List(HTTP_header) headers + ) = + if headers is + { + [ ] then [ ], + [h . t] then + append(server_get_cookies(h), server_get_cookies(t)) + }. + public define Maybe(Cookie) find_cookie ( diff --git a/calexium_lib/web/CXM_html.anubis b/calexium_lib/web/CXM_html.anubis index 441d387..0ad8cdc 100644 --- a/calexium_lib/web/CXM_html.anubis +++ b/calexium_lib/web/CXM_html.anubis @@ -6,7 +6,7 @@ read tools/basis.anubis read system/string.anubis - +read tools/printable_tree.anubis *** Managing Web Arguments. @@ -837,7 +837,7 @@ define Printable_tree ) = [(String)format_without_sharp(c)]. -define Printable_tree + define Printable_tree [Word32 x . Printable_tree t] = [to_Int(x) . t]. diff --git a/calexium_lib/web/CXM_making_a_web_site.anubis b/calexium_lib/web/CXM_making_a_web_site.anubis index 1b3871a..3556102 100644 --- a/calexium_lib/web/CXM_making_a_web_site.anubis +++ b/calexium_lib/web/CXM_making_a_web_site.anubis @@ -51,7 +51,7 @@ read system/logger.anubis read CXM_common.anubis read CXM_multihost_http_server.anubis read CXM_mime.anubis - +read CXM_cookies.anubis * (1) Structure of a web site. @@ -2057,49 +2057,54 @@ type Separated_Web_Args($State): The next function constructs the function which separates the web arguments. -define (List(Web_arg) lwa) -> Separated_Web_Args($State) +define (List(Web_arg) lwa, HTTP_Info info) -> Separated_Web_Args($State) make_separate_web_args_function ( String state_directory, String -> PreviousState($State) retrieve_state ) = - (List(Web_arg) lwa) |-swaf-> - if lwa is - { - [ ] then + (List(Web_arg) lwa, HTTP_Info info) |-swaf-> + if lwa is + { + [ ] then // // no web arg found => no previous state and no action // - swa(failure,failure,[]), + if find_cookie("s", server_get_cookies(http_headers(info))) is + { + failure then swa(failure,failure,[]), + success(cookie) then swa(success(retrieve_state(value(cookie))),failure,[]) + }, + + //swa(failure,failure,[]), - [wa_1 . wa_others] then + [wa_1 . wa_others] then // // at least one web arg => // separate other web args, and insert the first one as needed // - if (Separated_Web_Args($State))swaf(wa_others) is - { - swa(ps1, // possible previous state - an1, // maybe an action name - op1) // operands so far - then - if wa_1 is - { - web_arg(n, value) then - with name = if substr(n,0,4) = "amp;" then substr(n, 4, length(n) - 4) else n, - if name = "s" then - swa(success(retrieve_state(value)),an1,op1) - else if name = "a" then - swa(ps1,success(value),op1) - else if name = "t" then - swa(ps1,an1,[web_arg("target",value) . op1]) - else - swa(ps1,an1,[web_arg(name,value) . op1]), - - upload(n,v,t) then - swa(ps1,an1,[wa_1 . op1]) - }} - }. + if (Separated_Web_Args($State))swaf(wa_others, info) is + { + swa(ps1, // possible previous state + an1, // maybe an action name + op1) // operands so far + then + if wa_1 is + { + web_arg(n, value) then + with name = if substr(n,0,4) = "amp;" then substr(n, 4, length(n) - 4) else n, + if name = "a" then + swa(ps1,success(value),op1) + else if name = "t" then + swa(ps1,an1,[web_arg("target",value) . op1]) + else + swa(ps1,an1,[web_arg(name,value) . op1]), + + upload(n,v,t) then + swa(ps1,an1,[wa_1 . op1]) + } + } + }. @@ -2277,8 +2282,8 @@ public define Web_Site String secret, List(MIME) known_mime_types, (String action_name, - List(Web_arg) args) -> One before_send_file, - Bool using_state_cookies + List(Web_arg) args) -> One before_send_file + //Bool using_state_cookies ) = init(unique); @@ -2306,7 +2311,7 @@ public define Web_Site List(Web_arg) lwa, Bool is_https) |-> (Printable_tree) - if separate_web_args(lwa) is + if separate_web_args(lwa, http_info) is { swa(mb_previous_state,mb_action_name,operands) then with state_and_headers = if mb_previous_state is @@ -2342,7 +2347,7 @@ public define Web_Site }, if state_and_headers is (session_ticket, mb_new_state, headers) then with state_name = save_state(mb_new_state), - with cookie_headers = if using_state_cookies then make_state_cookie_headers(state_name) else [], + with cookie_headers = /* if using_state_cookies then */ make_state_cookie_headers(state_name) /*else [] */, format(info(host_name, http_port, https_port, site_directory, secret), state_name, headers + cookie_headers, @@ -2369,14 +2374,14 @@ public define Web_Site secret, known_mime_types, site_handler(http_port,https_port), - (List(Web_arg) lwa) |-> if separate_web_args(lwa) is + (HTTP_Info http_info, List(Web_arg) lwa) |-> if separate_web_args(lwa, http_info ) is swa(mb_previous_state,mb_action_name,operands) then if mb_action_name is { failure then unique success(an) then before_send_file(an,operands) - }, - using_state_cookies + } + //using_state_cookies ), delete_out_of_date). @@ -2886,7 +2891,7 @@ define String http then "http://"+common_name+":"+http_port+"/", https then "https://"+common_name+":"+https_port+"/", } + - "?s=" + state_name + "&a=" + action_name + + "?a=" + action_name + format_extra_operands(extra_ops), if target is { diff --git a/calexium_lib/web/CXM_multihost_http_server.anubis b/calexium_lib/web/CXM_multihost_http_server.anubis index 2b13d4a..b3404b6 100644 --- a/calexium_lib/web/CXM_multihost_http_server.anubis +++ b/calexium_lib/web/CXM_multihost_http_server.anubis @@ -210,8 +210,9 @@ public type Web_Site_Description: HTTP_Info http_info, List(Web_arg) lwa, Bool is_https) -> (Printable_tree) awp_handler, - (List(Web_arg) lwa) -> One before_send_file, - Bool using_state_cookies, + (HTTP_Info http_info, + List(Web_arg) lwa) -> One before_send_file + //Bool using_state_cookies, ). The component 'common_names' is the list of names of the site, like for example @@ -2353,6 +2354,7 @@ define One read_www_url_encoded_web_args(to_string(body),0), uri = uri(request_line), ext = get_uri_extension(uri), + http_inf = http_info(ip_addr, host_name, uri, headers, is_SSL(connection), generate_tt), (if member(journal_extensions(desc),ext) then log_journal_msg(desc, format_request(desc,connection,request_line,headers,all_web_args)) @@ -2361,7 +2363,7 @@ define One then log_journal_msg(desc,"Received illegal URI: "+uri+"\n") else (if (ext = ".awp" | ext = "") then (with answer_headers_body = awp_handler(desc)(host_name, - http_info(ip_addr, host_name, uri, headers, is_SSL(connection), generate_tt), + http_inf, all_web_args, is_SSL(connection)), //print_delta("After page generation"); @@ -2378,7 +2380,7 @@ define One not_found then failure, found(v) then success(v) }, - (One u) |-> before_send_file(desc)(all_web_args)) + (One u) |-> before_send_file(desc)(http_inf, all_web_args)) //print_delta("After sending file") )). @@ -3005,7 +3007,7 @@ define Maybe((String,Web_Site_Description)) { [ ] then print("Requested host '"+requested_host+"' does not exist.\n"); failure, [site1 . others] then - if site1 is web_site_description(common_names,_,_,_,_,_,_,_,_,_,_) then + if site1 is web_site_description(common_names,_,_,_,_,_,_,_,_,_) then if member(common_names,requested_host) then success((requested_host,site1)) else get_site(requested_host,others) -- libgit2 0.21.4