Commit 0e2959c0dc05c7ceb4ac98c02262cd2c4567240a
1 parent
09aeddee
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.
Showing
1 changed file
with
37 additions
and
21 deletions
Show diff stats
web/CXM_making_a_web_site.anubis
| @@ -1836,6 +1836,7 @@ define (String state_name) -> PreviousState($State) | @@ -1836,6 +1836,7 @@ define (String state_name) -> PreviousState($State) | ||
| 1836 | ) = | 1836 | ) = |
| 1837 | (String state_name) |-> | 1837 | (String state_name) |-> |
| 1838 | with file_path = state_directory+"/s"+state_name, | 1838 | with file_path = state_directory+"/s"+state_name, |
| 1839 | + //println("Retreive state ["+file_path+"]"); | ||
| 1839 | if (RetrieveResult((Int,$State)))retrieve(file_path) is ok(d) | 1840 | if (RetrieveResult((Int,$State)))retrieve(file_path) is ok(d) |
| 1840 | then ( | 1841 | then ( |
| 1841 | if d is (time_stamp,s) then | 1842 | if d is (time_stamp,s) then |
| @@ -2098,7 +2099,7 @@ define (List(Web_arg) lwa, HTTP_Info info) -> Separated_Web_Args($State) | @@ -2098,7 +2099,7 @@ define (List(Web_arg) lwa, HTTP_Info info) -> Separated_Web_Args($State) | ||
| 2098 | // | 2099 | // |
| 2099 | // no web arg found => no previous state and no action | 2100 | // no web arg found => no previous state and no action |
| 2100 | // | 2101 | // |
| 2101 | - if find_cookie("s", server_get_cookies(http_headers(info))) is | 2102 | + if find_cookie("state", server_get_cookies(http_headers(info))) is |
| 2102 | { | 2103 | { |
| 2103 | failure then swa(not_found,failure,[]), | 2104 | failure then swa(not_found,failure,[]), |
| 2104 | success(cookie) then swa(retrieve_state(value(cookie)),failure,[]) | 2105 | success(cookie) then swa(retrieve_state(value(cookie)),failure,[]) |
| @@ -2163,7 +2164,8 @@ define ($State previous, | @@ -2163,7 +2164,8 @@ define ($State previous, | ||
| 2163 | HTTP_Info http_info, | 2164 | HTTP_Info http_info, |
| 2164 | List(Web_arg) lwa, | 2165 | List(Web_arg) lwa, |
| 2165 | Bool is_https, | 2166 | Bool is_https, |
| 2166 | - List(Web_Action($State)) actions) |-f-> | 2167 | + List(Web_Action($State)) actions) |-f-> |
| 2168 | + //println("Looking for action ["+action_name+"]"); | ||
| 2167 | if actions is | 2169 | if actions is |
| 2168 | { | 2170 | { |
| 2169 | [ ] then print("action '"+action_name+ | 2171 | [ ] then print("action '"+action_name+ |
| @@ -2194,7 +2196,9 @@ define ($State previous, | @@ -2194,7 +2196,9 @@ define ($State previous, | ||
| 2194 | 2196 | ||
| 2195 | http_https_action(an,allow,do_it) then | 2197 | http_https_action(an,allow,do_it) then |
| 2196 | if an = action_name | 2198 | if an = action_name |
| 2197 | - then if allow(previous) | 2199 | + then |
| 2200 | + //println("Action ["+action_name+"] found"); | ||
| 2201 | + if allow(previous) | ||
| 2198 | then do_it(http_info,lwa,previous) | 2202 | then do_it(http_info,lwa,previous) |
| 2199 | else previous | 2203 | else previous |
| 2200 | else f(previous,action_name,http_info,lwa,is_https,others), | 2204 | else f(previous,action_name,http_info,lwa,is_https,others), |
| @@ -2277,7 +2281,7 @@ define List(HTTP_header) | @@ -2277,7 +2281,7 @@ define List(HTTP_header) | ||
| 2277 | ) | 2281 | ) |
| 2278 | = | 2282 | = |
| 2279 | [ | 2283 | [ |
| 2280 | - http_header("Set-Cookie", "s="+state_name) | 2284 | + http_header("Set-Cookie", "state="+state_name) |
| 2281 | ] | 2285 | ] |
| 2282 | . | 2286 | . |
| 2283 | 2287 | ||
| @@ -2361,9 +2365,9 @@ public define Web_Site | @@ -2361,9 +2365,9 @@ public define Web_Site | ||
| 2361 | // | 2365 | // |
| 2362 | // construct tool functions | 2366 | // construct tool functions |
| 2363 | // TODO 'make_separate_web_args_function' must retrieve state_cookies before parsing web_args if using_state_cookies is true | 2367 | // TODO 'make_separate_web_args_function' must retrieve state_cookies before parsing web_args if using_state_cookies is true |
| 2364 | - with save_state = make_save_state_function(timeout,state_directory), | 2368 | + with save_state = make_save_state_function(timeout, state_directory), |
| 2365 | retrieve_state = make_retrieve_state_function(state_directory), | 2369 | retrieve_state = make_retrieve_state_function(state_directory), |
| 2366 | - separate_web_args = make_separate_web_args_function(state_directory,retrieve_state), | 2370 | + separate_web_args = make_separate_web_args_function(state_directory, retrieve_state), |
| 2367 | apply_action = make_apply_action_function(actions), | 2371 | apply_action = make_apply_action_function(actions), |
| 2368 | // | 2372 | // |
| 2369 | // construct the site handler | 2373 | // construct the site handler |
| @@ -2376,10 +2380,11 @@ public define Web_Site | @@ -2376,10 +2380,11 @@ public define Web_Site | ||
| 2376 | //(Printable_tree) | 2380 | //(Printable_tree) |
| 2377 | if separate_web_args(lwa, http_info) is | 2381 | if separate_web_args(lwa, http_info) is |
| 2378 | { | 2382 | { |
| 2379 | - swa(mb_previous_state,mb_action_name,operands) then | 2383 | + swa(mb_previous_state, mb_action_name, operands) then |
| 2380 | with new_state = if mb_previous_state is | 2384 | with new_state = if mb_previous_state is |
| 2381 | { | 2385 | { |
| 2382 | not_found then | 2386 | not_found then |
| 2387 | + //println("previous state not found"); | ||
| 2383 | if mb_action_name is | 2388 | if mb_action_name is |
| 2384 | { | 2389 | { |
| 2385 | failure then initial_state(http_info, operands, is_https), | 2390 | failure then initial_state(http_info, operands, is_https), |
| @@ -2400,6 +2405,7 @@ public define Web_Site | @@ -2400,6 +2405,7 @@ public define Web_Site | ||
| 2400 | }, | 2405 | }, |
| 2401 | //if state_and_headers is (session_ticket, mb_new_state, headers) then | 2406 | //if state_and_headers is (session_ticket, mb_new_state, headers) then |
| 2402 | with state_name = save_state(new_state), | 2407 | with state_name = save_state(new_state), |
| 2408 | + //println("Cookie new STATE NAME "+state_name); | ||
| 2403 | with cookie_headers = /* if using_state_cookies then */ make_state_cookie_headers(state_name) /*else [] */, | 2409 | with cookie_headers = /* if using_state_cookies then */ make_state_cookie_headers(state_name) /*else [] */, |
| 2404 | format(info(host_name, http_port, https_port, site_directory, secret), | 2410 | format(info(host_name, http_port, https_port, site_directory, secret), |
| 2405 | state_name, | 2411 | state_name, |
| @@ -4391,15 +4397,15 @@ define Printable_tree | @@ -4391,15 +4397,15 @@ define Printable_tree | ||
| 4391 | meta(meta) then | 4397 | meta(meta) then |
| 4392 | [format(meta) . _format_html_head(t, so_far)], | 4398 | [format(meta) . _format_html_head(t, so_far)], |
| 4393 | title(title) then | 4399 | title(title) then |
| 4394 | - ["<title>"+title+"</title>" . _format_html_head(t, so_far)], | 4400 | + ["<title>"+title+"</title>\n" . _format_html_head(t, so_far)], |
| 4395 | js(jsf) then | 4401 | js(jsf) then |
| 4396 | [add_js_files([jsf]) . _format_html_head(t, so_far)], | 4402 | [add_js_files([jsf]) . _format_html_head(t, so_far)], |
| 4397 | js_inline(jsi) then | 4403 | js_inline(jsi) then |
| 4398 | - ["<script>"+content(jsi)+"</script>" . _format_html_head(t, so_far)], | 4404 | + ["<script>"+content(jsi)+"</script>\n" . _format_html_head(t, so_far)], |
| 4399 | css(cssf) then | 4405 | css(cssf) then |
| 4400 | - ["<link rel=\"stylesheet\" type=\"text/css\" href=\""+file_name(cssf)+"\">" . _format_html_head(t, so_far)], | 4406 | + ["<link rel=\"stylesheet\" type=\"text/css\" href=\""+file_name(cssf)+"\" />\n" . _format_html_head(t, so_far)], |
| 4401 | css_inline(cssi) then | 4407 | css_inline(cssi) then |
| 4402 | - ["<style>"+cssi+"</style>" . _format_html_head(t, so_far)] | 4408 | + ["<style>"+cssi+"</style>\n" . _format_html_head(t, so_far)] |
| 4403 | } | 4409 | } |
| 4404 | } | 4410 | } |
| 4405 | . | 4411 | . |
| @@ -4438,16 +4444,26 @@ define Printable_tree | @@ -4438,16 +4444,26 @@ define Printable_tree | ||
| 4438 | html_page(status, head_tags, body) then | 4444 | html_page(status, head_tags, body) then |
| 4439 | if body is body(options,element) then | 4445 | if body is body(options,element) then |
| 4440 | if format(status) is (status_string, status_headers) then | 4446 | if format(status) is (status_string, status_headers) then |
| 4441 | - [doctype_w3c_header, | ||
| 4442 | - html_header, | ||
| 4443 | - | ||
| 4444 | - format_html_head(head_tags, charset), | ||
| 4445 | - | ||
| 4446 | - "<body ", format(options), ">", // format body options | ||
| 4447 | - format(cinfo,state_name,ic_v,element,is_https), | ||
| 4448 | - "</body>\n", | ||
| 4449 | - | ||
| 4450 | - "</html>"], | 4447 | + with answer_body = |
| 4448 | + [doctype_w3c_header, | ||
| 4449 | + html_header, | ||
| 4450 | + | ||
| 4451 | + "<head>\n", format_html_head(head_tags, charset),"</head>\n", | ||
| 4452 | + | ||
| 4453 | + "<body ", format(options), ">", // format body options | ||
| 4454 | + format(cinfo,state_name,ic_v,element,is_https), | ||
| 4455 | + "</body>\n", | ||
| 4456 | + | ||
| 4457 | + "</html>"], | ||
| 4458 | + [ "HTTP/1.1 " + status_string, crlf, | ||
| 4459 | + format_headers(standard_headers), | ||
| 4460 | + format_headers(standard_headers_for("text/html", length(answer_body), success(charset))), | ||
| 4461 | + format_headers(status_headers), | ||
| 4462 | + format_headers(additional_headers), | ||
| 4463 | + crlf | ||
| 4464 | + . answer_body | ||
| 4465 | + ] | ||
| 4466 | + | ||
| 4451 | html_page(status, title, metas, css_styles, css_files, js_files, script, body) then | 4467 | html_page(status, title, metas, css_styles, css_files, js_files, script, body) then |
| 4452 | if body is body(options,element) then | 4468 | if body is body(options,element) then |
| 4453 | if format(status) is (status_string, status_headers) then | 4469 | if format(status) is (status_string, status_headers) then |