Commit 32f8435d8a643921caadf22d6eaac3af41665bb3

Authored by totoro
1 parent e37ba660

in web_session change lwa as Var in web_request

add helper functions in for adding, removing and replacing web_arg in var list web_arg
web/CXM_making_a_web_site.anubis
... ... @@ -3445,14 +3445,14 @@ define (Maybe(WEB_Session), HTTP_Answer)
3445 3445 WEB_Session _session,
3446 3446 Maybe(String) _mb_action_name,
3447 3447 (HTTP_Info,
3448   - List(Web_arg),
  3448 + Var(List(Web_arg)),
3449 3449 Bool is_https) -> WEB_Session initial_session,
3450 3450 )=
3451 3451 //get the action name
3452 3452 with mb_action_name =
3453 3453 if _mb_action_name is
3454 3454 {
3455   - failure then get_String(_session.web_request.lwa, "aws_action"),
  3455 + failure then get_String(*_session.web_request.lwa, "aws_action"),
3456 3456 success(_an) then success(_an)
3457 3457 },
3458 3458  
... ... @@ -3461,7 +3461,7 @@ define (Maybe(WEB_Session), HTTP_Answer)
3461 3461 failure then
3462 3462 //(failure, error_page(http_not_found, "Action name failure", _session)),
3463 3463 with new_session = initial_session(_session.web_request.http_info, _session.web_request.lwa, _session.web_request.is_https),
3464   - if get_controller(get_String(new_session.web_request.lwa, "aws_controller", "root"), controllers) is
  3464 + if get_controller(get_String(*new_session.web_request.lwa, "aws_controller", "root"), controllers) is
3465 3465 {
3466 3466 failure then (failure, error_page(http_not_found, "Initial Session Controller not found", new_session)),
3467 3467 success(new_controller) then apply_controller_action(new_controller, controllers, cinfo, new_session, failure, initial_session),
... ... @@ -3473,7 +3473,7 @@ define (Maybe(WEB_Session), HTTP_Answer)
3473 3473 http_answer(session, answer) then (success(session), answer),
3474 3474 http_answer(answer) then (success(_session), answer),
3475 3475 redirect(new_session) then
3476   - if get_controller(get_String(new_session.web_request.lwa, "aws_controller", "root"), controllers) is
  3476 + if get_controller(get_String(*new_session.web_request.lwa, "aws_controller", "root"), controllers) is
3477 3477 {
3478 3478 failure then (failure, error_page(http_not_found, "Redirect Controller not found", new_session)),
3479 3479 success(new_controller) then apply_controller_action(new_controller, controllers, cinfo, new_session, failure, initial_session),
... ... @@ -3488,7 +3488,7 @@ define (Maybe(WEB_Session), HTTP_Answer)
3488 3488 },
3489 3489  
3490 3490 redirect_to_previous then
3491   - if get_controller(get_String(_session.previous_web_request.lwa, "aws_controller", "root"), controllers) is
  3491 + if get_controller(get_String(*_session.previous_web_request.lwa, "aws_controller", "root"), controllers) is
3492 3492 {
3493 3493 failure then (failure, error_page(http_not_found, "Redirect to previous Controller not found", _session)),
3494 3494 success(new_controller) then
... ... @@ -3496,7 +3496,7 @@ define (Maybe(WEB_Session), HTTP_Answer)
3496 3496 apply_controller_action(new_controller, controllers, cinfo, web_session(lang, entries, previous, previous), failure, initial_session),
3497 3497 },
3498 3498 redirect_to_previous(entries) then
3499   - if get_controller(get_String(_session.previous_web_request.lwa, "aws_controller", "root"), controllers) is
  3499 + if get_controller(get_String(*_session.previous_web_request.lwa, "aws_controller", "root"), controllers) is
3500 3500 {
3501 3501 failure then (failure, error_page(http_not_found, "Redirect to previous Controller not found", _session)),
3502 3502 success(new_controller) then
... ... @@ -3525,11 +3525,11 @@ public define Web_Site
3525 3525 String state_directory,
3526 3526 One -> One init,
3527 3527 (HTTP_Info,
3528   - List(Web_arg),
  3528 + Var(List(Web_arg)),
3529 3529 Bool is_https) -> WEB_Session initial_session,
3530 3530 (WEB_Session,
3531 3531 HTTP_Info,
3532   - List(Web_arg),
  3532 + Var(List(Web_arg)),
3533 3533 Bool is_https) -> WEB_Session expired_session,
3534 3534 Var(List(WEB_Controller)) web_controllers,
3535 3535 Maybe(WEB_Session) -> List(HTTP_header) additional_headers,
... ... @@ -3567,10 +3567,10 @@ public define Web_Site
3567 3567 // construct the site handler
3568 3568 //
3569 3569 site_handler = (Word32 http_port, Word32 https_port) |->
3570   - ((String host_name,
3571   - HTTP_Info http_info,
3572   - List(Web_arg) _lwa,
3573   - Bool is_https) |->
  3570 + ((String host_name,
  3571 + HTTP_Info http_info,
  3572 + List(Web_arg) _lwa,
  3573 + Bool is_https) |->
3574 3574 //(Printable_tree)
3575 3575 //println("host_name "+host_name);
3576 3576 //println(dump_http_info(http_info));
... ... @@ -3582,21 +3582,21 @@ public define Web_Site
3582 3582 {
3583 3583 not_found then
3584 3584 //println("previous state not found");
3585   - initial_session(http_info, _lwa, is_https),
  3585 + initial_session(http_info, var(_lwa), is_https),
3586 3586  
3587 3587 out_of_date(previous_session) then
3588 3588 //println("previous out_of_date");
3589   - expired_session(previous_session, http_info, _lwa, is_https),
  3589 + expired_session(previous_session, http_info, var(_lwa), is_https),
3590 3590  
3591 3591 still_valid(previous_session) then
3592 3592 since previous_session is web_session(lang, entries, previous, _),
3593   - web_session(lang, entries, web_request(http_info, _lwa, is_https), previous)
  3593 + web_session(lang, entries, web_request(http_info, var(_lwa), is_https), previous)
3594 3594 },
3595 3595  
3596 3596  
3597 3597 //apply the action according to current session
3598 3598 //since apply_controller_action(get_controller(get_String(lwa, "aws_controller", "root"), *web_controllers), *web_controllers, current_session)
3599   - since if get_controller(get_String(current_session.web_request.lwa, "aws_controller", "root"), *web_controllers) is
  3599 + since if get_controller(get_String(*current_session.web_request.lwa, "aws_controller", "root"), *web_controllers) is
3600 3600 {
3601 3601 failure then
3602 3602 (failure, error_page(http_not_found, "Controller not found", current_session)),
... ...
web/CXM_web_arg_utils.anubis
... ... @@ -9,6 +9,46 @@ transmit tools/basis.anubis
9 9 transmit calexium_lib/web/CXM_common.anubis
10 10 transmit calexium_lib/database/db_types.anubis
11 11  
  12 +
  13 +public define One
  14 + add_web_arg
  15 + (
  16 + Var(List(Web_arg)) lwa,
  17 + String arg_name,
  18 + String value
  19 + )=
  20 + lwa <- [ web_arg(arg_name, value) . *lwa]
  21 +.
  22 +
  23 +public define One
  24 + add_web_arg
  25 + (
  26 + Var(List(Web_arg)) lwa,
  27 + Web_arg w_arg
  28 + )=
  29 + lwa <- [ w_arg . *lwa]
  30 +.
  31 +
  32 +public define One
  33 + remove_web_arg
  34 + (
  35 + Var(List(Web_arg)) lwa,
  36 + String arg_name
  37 + )=
  38 + lwa <- map_select((Web_arg w_arg) |-> if w_arg is web_arg(name, value) then if name = arg_name then failure else success(w_arg) else success(w_arg), *lwa)
  39 +.
  40 +
  41 +public define One
  42 + replace_web_arg
  43 + (
  44 + Var(List(Web_arg)) lwa,
  45 + String arg_name,
  46 + String value
  47 + )=
  48 + lwa <- map_select((Web_arg w_arg) |-> if w_arg is web_arg(name, value) then if name = arg_name then success(web_arg(name, value)) else success(w_arg) else success(w_arg), *lwa)
  49 +.
  50 +
  51 +
12 52 public define Maybe(DB_id)
13 53 get_mb_DB_id
14 54 (
... ...
web/CXM_web_session.anubis
... ... @@ -61,12 +61,20 @@ public type WEB_Session_Field_No_Var:
61 61  
62 62 public type WEB_Request:
63 63 web_request(
  64 + HTTP_Info http_info,
  65 + Var(List(Web_arg)) lwa,
  66 + Bool is_https,
  67 + )
  68 +.
  69 +
  70 +public type WEB_Request_No_Var:
  71 + web_request(
64 72 HTTP_Info http_info,
65 73 List(Web_arg) lwa,
66 74 Bool is_https,
67 75 )
68 76 .
69   -
  77 +
70 78 public type WEB_Session:
71 79 web_session(
72 80 String language,
... ... @@ -79,8 +87,8 @@ public type WEB_Session_No_Var:
79 87 web_session(
80 88 String language,
81 89 List(WEB_Session_Field_No_Var) fields,
82   - WEB_Request web_request,
83   - WEB_Request previous_web_request
  90 + WEB_Request_No_Var web_request,
  91 + WEB_Request_No_Var previous_web_request
84 92 ).
85 93  
86 94 public define Var(List(WEB_Session_Field))
... ... @@ -119,8 +127,11 @@ public define WEB_Session
119 127 (
120 128 WEB_Session_No_Var _session
121 129 )=
122   - since _session is web_session(language, fields, web_request, previous_web_request),
123   - web_session(language, to_WEB_Session_Field(fields), web_request, previous_web_request)
  130 + since _session is web_session(language, fields, c_web_request, p_web_request),
  131 + web_session(language, to_WEB_Session_Field(fields),
  132 + web_request(c_web_request.http_info, var(c_web_request.lwa), c_web_request.is_https),
  133 + web_request(p_web_request.http_info, var(p_web_request.lwa), p_web_request.is_https)
  134 + )
124 135 .
125 136  
126 137 public define WEB_Session_No_Var
... ... @@ -128,8 +139,11 @@ public define WEB_Session_No_Var
128 139 (
129 140 WEB_Session _session
130 141 )=
131   - since _session is web_session(language, fields, web_request, previous_web_request),
132   - web_session(language, to_WEB_Session_Field_No_Var(*fields), web_request, previous_web_request)
  142 + since _session is web_session(language, fields, c_web_request, p_web_request),
  143 + web_session(language, to_WEB_Session_Field_No_Var(*fields),
  144 + web_request(c_web_request.http_info, *c_web_request.lwa, c_web_request.is_https),
  145 + web_request(p_web_request.http_info, *p_web_request.lwa, p_web_request.is_https)
  146 + )
133 147 .
134 148  
135 149 public define Maybe(WEB_Session_Field_Datum)
... ... @@ -1125,7 +1139,7 @@ public define String
1125 1139 "http_info:\n"+
1126 1140 dump_http_info(web_request.http_info)+"\n"+
1127 1141 "web arguments:"+
1128   - dump_web_arg_values(web_request.lwa)+"\n\n"+
  1142 + dump_web_arg_values(*web_request.lwa)+"\n\n"+
1129 1143 "-----------------------------------------------------------------------------\n"+
1130 1144 "Previous WEB REQUEST:\n"+
1131 1145 "-----------------------------------------------------------------------------\n"+
... ... @@ -1133,6 +1147,6 @@ public define String
1133 1147 "http_info:\n"+
1134 1148 dump_http_info(previous_web_request.http_info)+"\n"+
1135 1149 "web arguments:"+
1136   - dump_web_arg_values(previous_web_request.lwa)+"\n"
  1150 + dump_web_arg_values(*previous_web_request.lwa)+"\n"
1137 1151  
1138 1152 .
... ...