Commit 1718a699c010470463df9498bac3ff72a559f409

Authored by Cédric RICARD
1 parent 912413bf

- 'shutdown' check has changed. Using a function instead a Boolean variable.

- HTTP redirect codes add needed 'Location' header.
calexium_lib/net_services/CXM_net_services.anubis
@@ -172,9 +172,8 @@ define Server -> (RWStream) -> One @@ -172,9 +172,8 @@ define Server -> (RWStream) -> One
172 public define Maybe(Server) 172 public define Maybe(Server)
173 start_net_services 173 start_net_services
174 ( 174 (
175 - List(NetService) net_services,  
176 - Word32 network_port,  
177 - Var(Bool) shutdown_required 175 + List(NetService) net_services,
  176 + Word32 network_port,
178 )= 177 )=
179 if start_server(0, 178 if start_server(0,
180 network_port, 179 network_port,
calexium_lib/web/CXM_making_a_web_site.anubis
@@ -589,7 +589,7 @@ public define Start_Web_Sites_Result @@ -589,7 +589,7 @@ public define Start_Web_Sites_Result
589 Word32 https_port, // usually: 443 589 Word32 https_port, // usually: 443
590 String ssl_certificate_common_name, 590 String ssl_certificate_common_name,
591 List(Web_Site) web_sites, // web sites to be started 591 List(Web_Site) web_sites, // web sites to be started
592 - Var(Bool) shutdown_required 592 + (One) -> Bool shutdown_required
593 ). 593 ).
594 594
595 'ip_address' is the IP address on which the two servers listen. If you put 0, the 595 'ip_address' is the IP address on which the two servers listen. If you put 0, the
@@ -1894,9 +1894,9 @@ define One @@ -1894,9 +1894,9 @@ define One
1894 Int next_time, 1894 Int next_time,
1895 Server http_server, 1895 Server http_server,
1896 Server https_server, 1896 Server https_server,
1897 - Var(Bool) shutdown_required 1897 + (One) -> Bool shutdown_required
1898 ) = 1898 ) =
1899 - if *shutdown_required 1899 + if shutdown_required(unique)
1900 then (shutdown(http_server); shutdown(https_server)) 1900 then (shutdown(http_server); shutdown(https_server))
1901 else unique; 1901 else unique;
1902 if (is_down(http_server) & is_down(https_server)) 1902 if (is_down(http_server) & is_down(https_server))
@@ -2370,7 +2370,7 @@ public define Start_Web_Sites_Result @@ -2370,7 +2370,7 @@ public define Start_Web_Sites_Result
2370 Word32 https_port, // usually: 443 2370 Word32 https_port, // usually: 443
2371 String ssl_certificate_common_name, 2371 String ssl_certificate_common_name,
2372 List(Web_Site) web_sites, // web sites to be started 2372 List(Web_Site) web_sites, // web sites to be started
2373 - Var(Bool) shutdown_required 2373 + (One) -> Bool shutdown_required
2374 ) = 2374 ) =
2375 with get_description = (Web_Site ws) |-> description(ws)(http_port,https_port), 2375 with get_description = (Web_Site ws) |-> description(ws)(http_port,https_port),
2376 with http_server_r = 2376 with http_server_r =
@@ -2422,7 +2422,7 @@ public define One @@ -2422,7 +2422,7 @@ public define One
2422 Word32 https_port, // usually: 443 2422 Word32 https_port, // usually: 443
2423 String ssl_certificate_common_name, 2423 String ssl_certificate_common_name,
2424 List(Web_Site) web_sites, // web sites to be started 2424 List(Web_Site) web_sites, // web sites to be started
2425 - Var(Bool) shutdown_required, 2425 + (One) -> Bool shutdown_required,
2426 Logger log 2426 Logger log
2427 ) = 2427 ) =
2428 if (Start_Web_Sites_Result)start_web_sites(ip_address, 2428 if (Start_Web_Sites_Result)start_web_sites(ip_address,
@@ -4293,6 +4293,7 @@ define Printable_tree @@ -4293,6 +4293,7 @@ define Printable_tree
4293 { 4293 {
4294 html_page(status, title, metas, css_styles, css_files, js_files, body) then 4294 html_page(status, title, metas, css_styles, css_files, js_files, body) then
4295 if body is body(options,element) then 4295 if body is body(options,element) then
  4296 + if format(status) is (status_string, status_headers) then
4296 with answer_body = 4297 with answer_body =
4297 [ doctype_w3c_header, 4298 [ doctype_w3c_header,
4298 html_header, 4299 html_header,
@@ -4322,35 +4323,42 @@ define Printable_tree @@ -4322,35 +4323,42 @@ define Printable_tree
4322 "</body>\n", 4323 "</body>\n",
4323 "</html>" 4324 "</html>"
4324 ], 4325 ],
4325 - [ "HTTP/1.1 " + format(status), crlf, 4326 + [ "HTTP/1.1 " + status_string, crlf,
4326 format_headers(standard_headers), 4327 format_headers(standard_headers),
4327 format_headers(standard_headers_for("text/html", length(answer_body), success(charset))), 4328 format_headers(standard_headers_for("text/html", length(answer_body), success(charset))),
  4329 + format_headers(status_headers),
4328 format_headers(additional_headers), 4330 format_headers(additional_headers),
4329 crlf 4331 crlf
4330 . answer_body 4332 . answer_body
4331 ], 4333 ],
4332 4334
4333 plain_text (HTTP_Status status, String text) then 4335 plain_text (HTTP_Status status, String text) then
4334 - [ "HTTP/1.1 " + format(status), crlf, 4336 + if format(status) is (status_string, status_headers) then
  4337 + [ "HTTP/1.1 " + status_string, crlf,
4335 format_headers(standard_headers), 4338 format_headers(standard_headers),
4336 format_headers(standard_headers_for("text/plain", length(text), success(charset))), 4339 format_headers(standard_headers_for("text/plain", length(text), success(charset))),
  4340 + format_headers(status_headers),
4337 format_headers(additional_headers), 4341 format_headers(additional_headers),
4338 crlf, 4342 crlf,
4339 text . (Printable_tree)[] 4343 text . (Printable_tree)[]
4340 ], 4344 ],
4341 4345
4342 custom_text(HTTP_Status status, String mime_type, String content) then 4346 custom_text(HTTP_Status status, String mime_type, String content) then
4343 - [ "HTTP/1.1 " + format(status), crlf, 4347 + if format(status) is (status_string, status_headers) then
  4348 + [ "HTTP/1.1 " + status_string, crlf,
4344 format_headers(standard_headers), 4349 format_headers(standard_headers),
4345 format_headers(standard_headers_for(mime_type, length(content), success(charset))), 4350 format_headers(standard_headers_for(mime_type, length(content), success(charset))),
  4351 + format_headers(status_headers),
4346 format_headers(additional_headers), 4352 format_headers(additional_headers),
4347 crlf, 4353 crlf,
4348 content . (Printable_tree)[] 4354 content . (Printable_tree)[]
4349 ], 4355 ],
4350 custom_binary(HTTP_Status status, String mime_type, ByteArray content, List(HTTP_header) other_headers) then 4356 custom_binary(HTTP_Status status, String mime_type, ByteArray content, List(HTTP_header) other_headers) then
4351 - [ "HTTP/1.1 " + format(status), crlf,  
4352 - format_headers(standard_headers), 4357 + if format(status) is (status_string, status_headers) then
  4358 + [ "HTTP/1.1 " + status_string, crlf,
  4359 + format_headers(status_headers),
4353 format_headers(standard_headers_for(mime_type, length(content), failure)), 4360 format_headers(standard_headers_for(mime_type, length(content), failure)),
  4361 + format_headers(status_headers),
4354 format_headers(other_headers), 4362 format_headers(other_headers),
4355 format_headers(additional_headers), 4363 format_headers(additional_headers),
4356 crlf, 4364 crlf,
@@ -4358,9 +4366,11 @@ define Printable_tree @@ -4358,9 +4366,11 @@ define Printable_tree
4358 ], 4366 ],
4359 4367
4360 custom_tree(HTTP_Status status, String mime_type, Printable_tree content) then 4368 custom_tree(HTTP_Status status, String mime_type, Printable_tree content) then
4361 - [ "HTTP/1.1 " + format(status), crlf, 4369 + if format(status) is (status_string, status_headers) then
  4370 + [ "HTTP/1.1 " + status_string, crlf,
4362 format_headers(standard_headers), 4371 format_headers(standard_headers),
4363 format_headers(standard_headers_for(mime_type, length(content), success(charset))), 4372 format_headers(standard_headers_for(mime_type, length(content), success(charset))),
  4373 + format_headers(status_headers),
4364 format_headers(additional_headers), 4374 format_headers(additional_headers),
4365 crlf . 4375 crlf .
4366 content 4376 content
@@ -4369,10 +4379,12 @@ define Printable_tree @@ -4369,10 +4379,12 @@ define Printable_tree
4369 http_raw(Printable_tree content) then content, 4379 http_raw(Printable_tree content) then content,
4370 4380
4371 html_content(HTTP_Status status, HTML_Off_Form content_HTML) then 4381 html_content(HTTP_Status status, HTML_Off_Form content_HTML) then
4372 - with content = format(cinfo, state_name, ic_v, content_HTML, is_https),  
4373 - [ "HTTP/1.1 " + format(status), crlf, 4382 + if format(status) is (status_string, status_headers) then
  4383 + with content = format(cinfo, state_name, ic_v, content_HTML, is_https),
  4384 + [ "HTTP/1.1 " + status_string, crlf,
4374 format_headers(standard_headers), 4385 format_headers(standard_headers),
4375 format_headers(standard_headers_for("text/html", length(content), success(charset))), 4386 format_headers(standard_headers_for("text/html", length(content), success(charset))),
  4387 + format_headers(status_headers),
4376 format_headers(additional_headers), 4388 format_headers(additional_headers),
4377 crlf . 4389 crlf .
4378 content 4390 content
calexium_lib/web/CXM_multihost_http_server.anubis
@@ -182,9 +182,11 @@ read CXM_mime.anubis @@ -182,9 +182,11 @@ read CXM_mime.anubis
182 public type HTTP_Info: 182 public type HTTP_Info:
183 http_info 183 http_info
184 ( 184 (
185 - Word32 ip_address, // IP address of the client 185 + Word32 ip_address, // IP address of the client
  186 + String hostname, // hostname requested by the client
186 String uri, // URI requested by the client 187 String uri, // URI requested by the client
187 List(HTTP_header) http_headers, // HTTP headers sent by the client 188 List(HTTP_header) http_headers, // HTTP headers sent by the client
  189 + Bool is_https,
188 One -> String generate_trust_ticket // may be used against denial of 190 One -> String generate_trust_ticket // may be used against denial of
189 // service attacks 191 // service attacks
190 ). 192 ).
@@ -500,12 +502,12 @@ public type HTTP_Status: @@ -500,12 +502,12 @@ public type HTTP_Status:
500 http_partial_content, 502 http_partial_content,
501 503
502 http_multiple_choices, 504 http_multiple_choices,
503 - http_moved_permanently,  
504 - http_moved_temporarily,  
505 - http_see_other, 505 + http_moved_permanently(String location),
  506 + http_moved_temporarily(String location),
  507 + http_see_other(String location),
506 http_not_modified, 508 http_not_modified,
507 - http_use_proxy,  
508 - http_temporary_redirect, 509 + http_use_proxy(String location),
  510 + http_temporary_redirect(String location),
509 511
510 http_bad_request, 512 http_bad_request,
511 http_unauthorized, 513 http_unauthorized,
@@ -535,7 +537,7 @@ public type HTTP_Status: @@ -535,7 +537,7 @@ public type HTTP_Status:
535 537
536 http_error(Int /*code*/, String /*message*/). 538 http_error(Int /*code*/, String /*message*/).
537 539
538 -public define String 540 +public define (String, List(HTTP_header))
539 format 541 format
540 ( 542 (
541 HTTP_Status status 543 HTTP_Status status
@@ -2357,7 +2359,7 @@ define One @@ -2357,7 +2359,7 @@ define One
2357 then log_journal_msg(desc,"Received illegal URI: "+uri+"\n") 2359 then log_journal_msg(desc,"Received illegal URI: "+uri+"\n")
2358 else (if (ext = ".awp" | ext = "") 2360 else (if (ext = ".awp" | ext = "")
2359 then (with answer_headers_body = awp_handler(desc)(host_name, 2361 then (with answer_headers_body = awp_handler(desc)(host_name,
2360 - http_info(ip_addr,uri,headers,generate_tt), 2362 + http_info(ip_addr, host_name, uri, headers, is_SSL(connection), generate_tt),
2361 all_web_args, 2363 all_web_args,
2362 is_SSL(connection)), 2364 is_SSL(connection)),
2363 //print_delta("After page generation"); 2365 //print_delta("After page generation");
@@ -2808,7 +2810,7 @@ define One @@ -2808,7 +2810,7 @@ define One
2808 else 2810 else
2809 if (ext = ".awp" | ext = "") then 2811 if (ext = ".awp" | ext = "") then
2810 (with answer_headers_body = awp_handler(desc)(host_name, 2812 (with answer_headers_body = awp_handler(desc)(host_name,
2811 - http_info(ip_addr,uri,headers,generate_tt), 2813 + http_info(ip_addr, host_name, uri, headers, is_SSL(connection), generate_tt),
2812 all_web_args, 2814 all_web_args,
2813 is_SSL(connection)), 2815 is_SSL(connection)),
2814 forget(reliable_write(connection, answer_headers_body))) 2816 forget(reliable_write(connection, answer_headers_body)))
@@ -3930,59 +3932,59 @@ global define One @@ -3930,59 +3932,59 @@ global define One
3930 3932
3931 3933
3932 3934
3933 -public define String 3935 +public define (String, List(HTTP_header))
3934 format 3936 format
3935 ( 3937 (
3936 HTTP_Status status 3938 HTTP_Status status
3937 ) = 3939 ) =
3938 if status is 3940 if status is
3939 { 3941 {
3940 - http_continue then "100 Continue",  
3941 - http_switching_protocol then "101 Switching Protocols", 3942 + http_continue then ("100 Continue", []),
  3943 + http_switching_protocol then ("101 Switching Protocols", []),
3942 3944
3943 - http_ok then "200 OK",  
3944 - http_created then "201 Created",  
3945 - http_accepted then "202 Accepted",  
3946 - http_non_authoritative_info then "203 Non-Authoritative Information",  
3947 - http_no_content then "204 No Content",  
3948 - http_reset_content then "205 Reset Content",  
3949 - http_partial_content then "206 Partial Content", 3945 + http_ok then ("200 OK", []),
  3946 + http_created then ("201 Created", []),
  3947 + http_accepted then ("202 Accepted", []),
  3948 + http_non_authoritative_info then ("203 Non-Authoritative Information", []),
  3949 + http_no_content then ("204 No Content", []),
  3950 + http_reset_content then ("205 Reset Content", []),
  3951 + http_partial_content then ("206 Partial Content", []),
3950 3952
3951 - http_multiple_choices then "300 Multiple Choices",  
3952 - http_moved_permanently then "301 Moved Permanently",  
3953 - http_moved_temporarily then "302 Moved Temporarily",  
3954 - http_see_other then "303 See Other",  
3955 - http_not_modified then "304 Not Modified",  
3956 - http_use_proxy then "305 Use Proxy",  
3957 - http_temporary_redirect then "307 Temporary Redirect", 3953 + http_multiple_choices then ("300 Multiple Choices", []),
  3954 + http_moved_permanently(loc) then ("301 Moved Permanently", [http_header("Location", loc)]),
  3955 + http_moved_temporarily(loc) then ("302 Moved Temporarily", [http_header("Location", loc)]),
  3956 + http_see_other(loc) then ("303 See Other", [http_header("Location", loc)]),
  3957 + http_not_modified then ("304 Not Modified", []),
  3958 + http_use_proxy(loc) then ("305 Use Proxy", [http_header("Location", loc)]),
  3959 + http_temporary_redirect(loc) then ("307 Temporary Redirect", [http_header("Location", loc)]),
3958 3960
3959 - http_bad_request then "400 Bad Request",  
3960 - http_unauthorized then "401 Unauthorized",  
3961 - http_payment_required then "402 Payment Required",  
3962 - http_forbidden then "403 Forbidden",  
3963 - http_not_found then "404 Not Found",  
3964 - http_method_not_allowed then "405 Method Not Allowed",  
3965 - http_not_acceptable then "406 Not Acceptable",  
3966 - http_proxy_authentification_required then "407 Proxy Authentication Required",  
3967 - http_request_timeout then "408 Request Time-out",  
3968 - http_conflict then "409 Conflict",  
3969 - http_gone then "410 Gone",  
3970 - http_length_required then "411 Length Required",  
3971 - http_precondition_failed then "412 Precondition Failed",  
3972 - http_request_entity_too_large then "413 Request Entity Too Large",  
3973 - http_request_uri_too_long then "414 Request-URI Too Long",  
3974 - http_unsupported_media_type then "415 Unsupported Media Type",  
3975 - http_request_range_unsatisfiable then "416 Requested range unsatisfiable",  
3976 - http_expectation_failed then "417 Expectation failed", 3961 + http_bad_request then ("400 Bad Request", []),
  3962 + http_unauthorized then ("401 Unauthorized", []),
  3963 + http_payment_required then ("402 Payment Required", []),
  3964 + http_forbidden then ("403 Forbidden", []),
  3965 + http_not_found then ("404 Not Found", []),
  3966 + http_method_not_allowed then ("405 Method Not Allowed", []),
  3967 + http_not_acceptable then ("406 Not Acceptable", []),
  3968 + http_proxy_authentification_required then ("407 Proxy Authentication Required", []),
  3969 + http_request_timeout then ("408 Request Time-out", []),
  3970 + http_conflict then ("409 Conflict", []),
  3971 + http_gone then ("410 Gone", []),
  3972 + http_length_required then ("411 Length Required", []),
  3973 + http_precondition_failed then ("412 Precondition Failed", []),
  3974 + http_request_entity_too_large then ("413 Request Entity Too Large", []),
  3975 + http_request_uri_too_long then ("414 Request-URI Too Long", []),
  3976 + http_unsupported_media_type then ("415 Unsupported Media Type", []),
  3977 + http_request_range_unsatisfiable then ("416 Requested range unsatisfiable", []),
  3978 + http_expectation_failed then ("417 Expectation failed", []),
3977 3979
3978 - http_internal_server_error then "500 Internal Server Error",  
3979 - http_not_implemented then "501 Not Implemented",  
3980 - http_bad_gateway then "502 Bad Gateway",  
3981 - http_service_unavailable then "503 Service Unavailable",  
3982 - http_gateway_timeout then "504 Gateway Time-out",  
3983 - http_version_not_supported then "505 HTTP Version not supported", 3980 + http_internal_server_error then ("500 Internal Server Error", []),
  3981 + http_not_implemented then ("501 Not Implemented", []),
  3982 + http_bad_gateway then ("502 Bad Gateway", []),
  3983 + http_service_unavailable then ("503 Service Unavailable", []),
  3984 + http_gateway_timeout then ("504 Gateway Time-out", []),
  3985 + http_version_not_supported then ("505 HTTP Version not supported", []),
3984 3986
3985 - http_error(code, message) then abs_to_decimal(code) + " " + message 3987 + http_error(code, message) then (abs_to_decimal(code) + " " + message, [])
3986 }. 3988 }.
3987 3989
3988 3990