Commit c39fad5bb124f8e9012bbae186c6e66c88bb2fa4

Authored by yekolia
1 parent abc3c314

Modification:

- Adding support of multi-site cookies
Showing 1 changed file with 46 additions and 6 deletions   Show diff stats
web/CXM_making_a_web_site.anubis
... ... @@ -2090,7 +2090,8 @@ define (List(Web_arg) lwa, HTTP_Info info) -> Separated_Web_Args($State)
2090 2090 make_separate_web_args_function
2091 2091 (
2092 2092 String state_directory,
2093   - String -> PreviousState($State) retrieve_state
  2093 + String -> PreviousState($State) retrieve_state,
  2094 + String website_name
2094 2095 ) =
2095 2096 (List(Web_arg) lwa, HTTP_Info info) |-swaf->
2096 2097 if lwa is
... ... @@ -2099,7 +2100,7 @@ define (List(Web_arg) lwa, HTTP_Info info) -> Separated_Web_Args($State)
2099 2100 //
2100 2101 // no web arg found => no previous state and no action
2101 2102 //
2102   - if find_cookie("state", server_get_cookies(http_headers(info))) is
  2103 + if find_cookie("state_"+website_name, server_get_cookies(http_headers(info))) is
2103 2104 {
2104 2105 failure then swa(not_found,failure,[]),
2105 2106 success(cookie) then swa(retrieve_state(value(cookie)),failure,[])
... ... @@ -2277,11 +2278,12 @@ define Printable_tree
2277 2278 define List(HTTP_header)
2278 2279 make_state_cookie_headers
2279 2280 (
  2281 + String website_name,
2280 2282 String state_name
2281 2283 )
2282 2284 =
2283 2285 [
2284   - http_header("Set-Cookie", "state="+state_name)
  2286 + http_header("Set-Cookie", "state_"+website_name+"="+state_name)
2285 2287 ]
2286 2288 .
2287 2289  
... ... @@ -2317,11 +2319,12 @@ define List(HTTP_header)
2317 2319 (String action_name,
2318 2320 List(Web_arg) args)-> One before_send_file
2319 2321 ).
2320   -
  2322 +
2321 2323  
2322 2324 public define Web_Site
2323 2325 make_web_site_description
2324 2326 (
  2327 + String website_name,
2325 2328 List(String) common_names, // for example: ["www.our-business.com"]
2326 2329 String site_directory,
2327 2330 String state_directory,
... ... @@ -2367,7 +2370,7 @@ public define Web_Site
2367 2370 // TODO 'make_separate_web_args_function' must retrieve state_cookies before parsing web_args if using_state_cookies is true
2368 2371 with save_state = make_save_state_function(timeout, state_directory),
2369 2372 retrieve_state = make_retrieve_state_function(state_directory),
2370   - separate_web_args = make_separate_web_args_function(state_directory, retrieve_state),
  2373 + separate_web_args = make_separate_web_args_function(state_directory, retrieve_state, website_name),
2371 2374 apply_action = make_apply_action_function(actions),
2372 2375 //
2373 2376 // construct the site handler
... ... @@ -2413,7 +2416,7 @@ public define Web_Site
2413 2416 if substr(action_name, 0, 5)="ajax_" then
2414 2417 []
2415 2418 else
2416   - make_state_cookie_headers(state_name)
  2419 + make_state_cookie_headers(website_name, state_name)
2417 2420 },
2418 2421  
2419 2422 format(info(host_name, http_port, https_port, site_directory, secret),
... ... @@ -2453,6 +2456,43 @@ public define Web_Site
2453 2456 ),
2454 2457 delete_out_of_date).
2455 2458  
  2459 +// Compatibility function for older websites
  2460 +public define Web_Site
  2461 + make_web_site_description
  2462 + (
  2463 + List(String) common_names, // for example: ["www.our-business.com"]
  2464 + String site_directory,
  2465 + String state_directory,
  2466 + One -> One init,
  2467 + (HTTP_Info,
  2468 + List(Web_arg),
  2469 + Bool is_https) -> $State initial_state,
  2470 + ($State expired,
  2471 + Maybe(String),
  2472 + HTTP_Info,
  2473 + List(Web_arg),
  2474 + Bool is_https) -> $State ticket_expired_state,
  2475 + (Maybe(String),
  2476 + HTTP_Info,
  2477 + List(Web_arg),
  2478 + Bool is_https) -> $State ticket_lost_state,
  2479 + List(Web_Action($State)) actions,
  2480 + $State -> HTTP_Answer compute_page,
  2481 + $State -> List(HTTP_header) additional_headers,
  2482 + Int timeout,
  2483 + Redirections redirections,
  2484 + String charset,
  2485 + List(String) journal_extensions,
  2486 + List(String) journal_headers,
  2487 + String secret,
  2488 + List(MIME) known_mime_types,
  2489 + (String action_name,
  2490 + List(Web_arg) args) -> One before_send_file
  2491 + //Bool using_state_cookies
  2492 + )
  2493 + =
  2494 + make_web_site_description("", common_names, site_directory, state_directory, init, initial_state, ticket_expired_state, ticket_lost_state, actions, compute_page, additional_headers, timeout, redirections, charset, journal_extensions, journal_headers, secret, known_mime_types, before_send_file)
  2495 + .
2456 2496  
2457 2497  
2458 2498  
... ...