From 1718a699c010470463df9498bac3ff72a559f409 Mon Sep 17 00:00:00 2001 From: Cedric RICARD Date: Thu, 29 Jan 2009 00:00:39 +0000 Subject: [PATCH] - '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 | 5 ++--- calexium_lib/web/CXM_making_a_web_site.anubis | 38 +++++++++++++++++++++++++------------- calexium_lib/web/CXM_multihost_http_server.anubis | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------- 3 files changed, 80 insertions(+), 67 deletions(-) diff --git a/calexium_lib/net_services/CXM_net_services.anubis b/calexium_lib/net_services/CXM_net_services.anubis index c6133be..d0ee882 100644 --- a/calexium_lib/net_services/CXM_net_services.anubis +++ b/calexium_lib/net_services/CXM_net_services.anubis @@ -172,9 +172,8 @@ define Server -> (RWStream) -> One public define Maybe(Server) start_net_services ( - List(NetService) net_services, - Word32 network_port, - Var(Bool) shutdown_required + List(NetService) net_services, + Word32 network_port, )= if start_server(0, network_port, diff --git a/calexium_lib/web/CXM_making_a_web_site.anubis b/calexium_lib/web/CXM_making_a_web_site.anubis index a68b81a..ab7e0e8 100644 --- a/calexium_lib/web/CXM_making_a_web_site.anubis +++ b/calexium_lib/web/CXM_making_a_web_site.anubis @@ -589,7 +589,7 @@ public define Start_Web_Sites_Result Word32 https_port, // usually: 443 String ssl_certificate_common_name, List(Web_Site) web_sites, // web sites to be started - Var(Bool) shutdown_required + (One) -> Bool shutdown_required ). 'ip_address' is the IP address on which the two servers listen. If you put 0, the @@ -1894,9 +1894,9 @@ define One Int next_time, Server http_server, Server https_server, - Var(Bool) shutdown_required + (One) -> Bool shutdown_required ) = - if *shutdown_required + if shutdown_required(unique) then (shutdown(http_server); shutdown(https_server)) else unique; if (is_down(http_server) & is_down(https_server)) @@ -2370,7 +2370,7 @@ public define Start_Web_Sites_Result Word32 https_port, // usually: 443 String ssl_certificate_common_name, List(Web_Site) web_sites, // web sites to be started - Var(Bool) shutdown_required + (One) -> Bool shutdown_required ) = with get_description = (Web_Site ws) |-> description(ws)(http_port,https_port), with http_server_r = @@ -2422,7 +2422,7 @@ public define One Word32 https_port, // usually: 443 String ssl_certificate_common_name, List(Web_Site) web_sites, // web sites to be started - Var(Bool) shutdown_required, + (One) -> Bool shutdown_required, Logger log ) = if (Start_Web_Sites_Result)start_web_sites(ip_address, @@ -4293,6 +4293,7 @@ define Printable_tree { html_page(status, title, metas, css_styles, css_files, js_files, body) then if body is body(options,element) then + if format(status) is (status_string, status_headers) then with answer_body = [ doctype_w3c_header, html_header, @@ -4322,35 +4323,42 @@ define Printable_tree "\n", "" ], - [ "HTTP/1.1 " + format(status), crlf, + [ "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 ], plain_text (HTTP_Status status, String text) then - [ "HTTP/1.1 " + format(status), crlf, + if format(status) is (status_string, status_headers) then + [ "HTTP/1.1 " + status_string, crlf, format_headers(standard_headers), format_headers(standard_headers_for("text/plain", length(text), success(charset))), + format_headers(status_headers), format_headers(additional_headers), crlf, text . (Printable_tree)[] ], custom_text(HTTP_Status status, String mime_type, String content) then - [ "HTTP/1.1 " + format(status), crlf, + if format(status) is (status_string, status_headers) then + [ "HTTP/1.1 " + status_string, crlf, format_headers(standard_headers), format_headers(standard_headers_for(mime_type, length(content), success(charset))), + format_headers(status_headers), format_headers(additional_headers), crlf, content . (Printable_tree)[] ], custom_binary(HTTP_Status status, String mime_type, ByteArray content, List(HTTP_header) other_headers) then - [ "HTTP/1.1 " + format(status), crlf, - format_headers(standard_headers), + if format(status) is (status_string, status_headers) then + [ "HTTP/1.1 " + status_string, crlf, + format_headers(status_headers), format_headers(standard_headers_for(mime_type, length(content), failure)), + format_headers(status_headers), format_headers(other_headers), format_headers(additional_headers), crlf, @@ -4358,9 +4366,11 @@ define Printable_tree ], custom_tree(HTTP_Status status, String mime_type, Printable_tree content) then - [ "HTTP/1.1 " + format(status), crlf, + if format(status) is (status_string, status_headers) then + [ "HTTP/1.1 " + status_string, crlf, format_headers(standard_headers), format_headers(standard_headers_for(mime_type, length(content), success(charset))), + format_headers(status_headers), format_headers(additional_headers), crlf . content @@ -4369,10 +4379,12 @@ define Printable_tree http_raw(Printable_tree content) then content, html_content(HTTP_Status status, HTML_Off_Form content_HTML) then - with content = format(cinfo, state_name, ic_v, content_HTML, is_https), - [ "HTTP/1.1 " + format(status), crlf, + if format(status) is (status_string, status_headers) then + with content = format(cinfo, state_name, ic_v, content_HTML, is_https), + [ "HTTP/1.1 " + status_string, crlf, format_headers(standard_headers), format_headers(standard_headers_for("text/html", length(content), success(charset))), + format_headers(status_headers), format_headers(additional_headers), crlf . content diff --git a/calexium_lib/web/CXM_multihost_http_server.anubis b/calexium_lib/web/CXM_multihost_http_server.anubis index 15fea47..c907c08 100644 --- a/calexium_lib/web/CXM_multihost_http_server.anubis +++ b/calexium_lib/web/CXM_multihost_http_server.anubis @@ -182,9 +182,11 @@ read CXM_mime.anubis public type HTTP_Info: http_info ( - Word32 ip_address, // IP address of the client + Word32 ip_address, // IP address of the client + String hostname, // hostname requested by the client String uri, // URI requested by the client List(HTTP_header) http_headers, // HTTP headers sent by the client + Bool is_https, One -> String generate_trust_ticket // may be used against denial of // service attacks ). @@ -500,12 +502,12 @@ public type HTTP_Status: http_partial_content, http_multiple_choices, - http_moved_permanently, - http_moved_temporarily, - http_see_other, + http_moved_permanently(String location), + http_moved_temporarily(String location), + http_see_other(String location), http_not_modified, - http_use_proxy, - http_temporary_redirect, + http_use_proxy(String location), + http_temporary_redirect(String location), http_bad_request, http_unauthorized, @@ -535,7 +537,7 @@ public type HTTP_Status: http_error(Int /*code*/, String /*message*/). -public define String +public define (String, List(HTTP_header)) format ( HTTP_Status status @@ -2357,7 +2359,7 @@ define One then log_journal_msg(desc,"Received illegal URI: "+uri+"\n") else (if (ext = ".awp" | ext = "") then (with answer_headers_body = awp_handler(desc)(host_name, - http_info(ip_addr,uri,headers,generate_tt), + http_info(ip_addr, host_name, uri, headers, is_SSL(connection), generate_tt), all_web_args, is_SSL(connection)), //print_delta("After page generation"); @@ -2808,7 +2810,7 @@ define One else if (ext = ".awp" | ext = "") then (with answer_headers_body = awp_handler(desc)(host_name, - http_info(ip_addr,uri,headers,generate_tt), + http_info(ip_addr, host_name, uri, headers, is_SSL(connection), generate_tt), all_web_args, is_SSL(connection)), forget(reliable_write(connection, answer_headers_body))) @@ -3930,59 +3932,59 @@ global define One -public define String +public define (String, List(HTTP_header)) format ( HTTP_Status status ) = if status is { - http_continue then "100 Continue", - http_switching_protocol then "101 Switching Protocols", + http_continue then ("100 Continue", []), + http_switching_protocol then ("101 Switching Protocols", []), - http_ok then "200 OK", - http_created then "201 Created", - http_accepted then "202 Accepted", - http_non_authoritative_info then "203 Non-Authoritative Information", - http_no_content then "204 No Content", - http_reset_content then "205 Reset Content", - http_partial_content then "206 Partial Content", + http_ok then ("200 OK", []), + http_created then ("201 Created", []), + http_accepted then ("202 Accepted", []), + http_non_authoritative_info then ("203 Non-Authoritative Information", []), + http_no_content then ("204 No Content", []), + http_reset_content then ("205 Reset Content", []), + http_partial_content then ("206 Partial Content", []), - http_multiple_choices then "300 Multiple Choices", - http_moved_permanently then "301 Moved Permanently", - http_moved_temporarily then "302 Moved Temporarily", - http_see_other then "303 See Other", - http_not_modified then "304 Not Modified", - http_use_proxy then "305 Use Proxy", - http_temporary_redirect then "307 Temporary Redirect", + http_multiple_choices then ("300 Multiple Choices", []), + http_moved_permanently(loc) then ("301 Moved Permanently", [http_header("Location", loc)]), + http_moved_temporarily(loc) then ("302 Moved Temporarily", [http_header("Location", loc)]), + http_see_other(loc) then ("303 See Other", [http_header("Location", loc)]), + http_not_modified then ("304 Not Modified", []), + http_use_proxy(loc) then ("305 Use Proxy", [http_header("Location", loc)]), + http_temporary_redirect(loc) then ("307 Temporary Redirect", [http_header("Location", loc)]), - http_bad_request then "400 Bad Request", - http_unauthorized then "401 Unauthorized", - http_payment_required then "402 Payment Required", - http_forbidden then "403 Forbidden", - http_not_found then "404 Not Found", - http_method_not_allowed then "405 Method Not Allowed", - http_not_acceptable then "406 Not Acceptable", - http_proxy_authentification_required then "407 Proxy Authentication Required", - http_request_timeout then "408 Request Time-out", - http_conflict then "409 Conflict", - http_gone then "410 Gone", - http_length_required then "411 Length Required", - http_precondition_failed then "412 Precondition Failed", - http_request_entity_too_large then "413 Request Entity Too Large", - http_request_uri_too_long then "414 Request-URI Too Long", - http_unsupported_media_type then "415 Unsupported Media Type", - http_request_range_unsatisfiable then "416 Requested range unsatisfiable", - http_expectation_failed then "417 Expectation failed", + http_bad_request then ("400 Bad Request", []), + http_unauthorized then ("401 Unauthorized", []), + http_payment_required then ("402 Payment Required", []), + http_forbidden then ("403 Forbidden", []), + http_not_found then ("404 Not Found", []), + http_method_not_allowed then ("405 Method Not Allowed", []), + http_not_acceptable then ("406 Not Acceptable", []), + http_proxy_authentification_required then ("407 Proxy Authentication Required", []), + http_request_timeout then ("408 Request Time-out", []), + http_conflict then ("409 Conflict", []), + http_gone then ("410 Gone", []), + http_length_required then ("411 Length Required", []), + http_precondition_failed then ("412 Precondition Failed", []), + http_request_entity_too_large then ("413 Request Entity Too Large", []), + http_request_uri_too_long then ("414 Request-URI Too Long", []), + http_unsupported_media_type then ("415 Unsupported Media Type", []), + http_request_range_unsatisfiable then ("416 Requested range unsatisfiable", []), + http_expectation_failed then ("417 Expectation failed", []), - http_internal_server_error then "500 Internal Server Error", - http_not_implemented then "501 Not Implemented", - http_bad_gateway then "502 Bad Gateway", - http_service_unavailable then "503 Service Unavailable", - http_gateway_timeout then "504 Gateway Time-out", - http_version_not_supported then "505 HTTP Version not supported", + http_internal_server_error then ("500 Internal Server Error", []), + http_not_implemented then ("501 Not Implemented", []), + http_bad_gateway then ("502 Bad Gateway", []), + http_service_unavailable then ("503 Service Unavailable", []), + http_gateway_timeout then ("504 Gateway Time-out", []), + http_version_not_supported then ("505 HTTP Version not supported", []), - http_error(code, message) then abs_to_decimal(code) + " " + message + http_error(code, message) then (abs_to_decimal(code) + " " + message, []) }. -- libgit2 0.21.4