From 0e2959c0dc05c7ceb4ac98c02262cd2c4567240a Mon Sep 17 00:00:00 2001 From: David RENE Date: Sun, 16 Sep 2012 00:04:25 +0000 Subject: [PATCH] Change the cookie name for state hash from 's' to 'state'. Fix a very serious bug introduced with new html_page alternative html_page(status, head_tags, body). This new alternative result returned the html body only. All http_header (http status, cookies, etc.) was forgotten. --- web/CXM_making_a_web_site.anubis | 58 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/web/CXM_making_a_web_site.anubis b/web/CXM_making_a_web_site.anubis index 82b704f..e0f4a1c 100644 --- a/web/CXM_making_a_web_site.anubis +++ b/web/CXM_making_a_web_site.anubis @@ -1836,6 +1836,7 @@ define (String state_name) -> PreviousState($State) ) = (String state_name) |-> with file_path = state_directory+"/s"+state_name, + //println("Retreive state ["+file_path+"]"); if (RetrieveResult((Int,$State)))retrieve(file_path) is ok(d) then ( if d is (time_stamp,s) then @@ -2098,7 +2099,7 @@ define (List(Web_arg) lwa, HTTP_Info info) -> Separated_Web_Args($State) // // no web arg found => no previous state and no action // - if find_cookie("s", server_get_cookies(http_headers(info))) is + if find_cookie("state", server_get_cookies(http_headers(info))) is { failure then swa(not_found,failure,[]), success(cookie) then swa(retrieve_state(value(cookie)),failure,[]) @@ -2163,7 +2164,8 @@ define ($State previous, HTTP_Info http_info, List(Web_arg) lwa, Bool is_https, - List(Web_Action($State)) actions) |-f-> + List(Web_Action($State)) actions) |-f-> + //println("Looking for action ["+action_name+"]"); if actions is { [ ] then print("action '"+action_name+ @@ -2194,7 +2196,9 @@ define ($State previous, http_https_action(an,allow,do_it) then if an = action_name - then if allow(previous) + then + //println("Action ["+action_name+"] found"); + if allow(previous) then do_it(http_info,lwa,previous) else previous else f(previous,action_name,http_info,lwa,is_https,others), @@ -2277,7 +2281,7 @@ define List(HTTP_header) ) = [ - http_header("Set-Cookie", "s="+state_name) + http_header("Set-Cookie", "state="+state_name) ] . @@ -2361,9 +2365,9 @@ public define Web_Site // // construct tool functions // TODO 'make_separate_web_args_function' must retrieve state_cookies before parsing web_args if using_state_cookies is true - with save_state = make_save_state_function(timeout,state_directory), + with save_state = make_save_state_function(timeout, state_directory), retrieve_state = make_retrieve_state_function(state_directory), - separate_web_args = make_separate_web_args_function(state_directory,retrieve_state), + separate_web_args = make_separate_web_args_function(state_directory, retrieve_state), apply_action = make_apply_action_function(actions), // // construct the site handler @@ -2376,10 +2380,11 @@ public define Web_Site //(Printable_tree) if separate_web_args(lwa, http_info) is { - swa(mb_previous_state,mb_action_name,operands) then + swa(mb_previous_state, mb_action_name, operands) then with new_state = if mb_previous_state is { not_found then + //println("previous state not found"); if mb_action_name is { failure then initial_state(http_info, operands, is_https), @@ -2400,6 +2405,7 @@ public define Web_Site }, //if state_and_headers is (session_ticket, mb_new_state, headers) then with state_name = save_state(new_state), + //println("Cookie new STATE NAME "+state_name); 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, @@ -4391,15 +4397,15 @@ define Printable_tree meta(meta) then [format(meta) . _format_html_head(t, so_far)], title(title) then - [""+title+"" . _format_html_head(t, so_far)], + [""+title+"\n" . _format_html_head(t, so_far)], js(jsf) then [add_js_files([jsf]) . _format_html_head(t, so_far)], js_inline(jsi) then - ["" . _format_html_head(t, so_far)], + ["\n" . _format_html_head(t, so_far)], css(cssf) then - ["" . _format_html_head(t, so_far)], + ["\n" . _format_html_head(t, so_far)], css_inline(cssi) then - ["" . _format_html_head(t, so_far)] + ["\n" . _format_html_head(t, so_far)] } } . @@ -4438,16 +4444,26 @@ define Printable_tree html_page(status, head_tags, body) then if body is body(options,element) then if format(status) is (status_string, status_headers) then - [doctype_w3c_header, - html_header, - - format_html_head(head_tags, charset), - - "", // format body options - format(cinfo,state_name,ic_v,element,is_https), - "\n", - - ""], + with answer_body = + [doctype_w3c_header, + html_header, + + "\n", format_html_head(head_tags, charset),"\n", + + "", // format body options + format(cinfo,state_name,ic_v,element,is_https), + "\n", + + ""], + [ "HTTP/1.1 " + status_string, crlf, + format_headers(standard_headers), + format_headers(standard_headers_for("text/html", length(answer_body), success(charset))), + format_headers(status_headers), + format_headers(additional_headers), + crlf + . answer_body + ] + html_page(status, title, metas, css_styles, css_files, js_files, script, body) then if body is body(options,element) then if format(status) is (status_string, status_headers) then -- libgit2 0.21.4