From 23f86e1ba365bedc9aaa4f239bb257f4326615e2 Mon Sep 17 00:00:00 2001 From: Cedric RICARD Date: Wed, 13 Aug 2008 16:56:22 +0000 Subject: [PATCH] Added HTTP error codes --- calexium_lib/web/CXM_making_a_web_site.anubis | 65 ++++++++++++++++++++++++++++++++++++----------------------------- calexium_lib/web/CXM_multihost_http_server.anubis | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 29 deletions(-) diff --git a/calexium_lib/web/CXM_making_a_web_site.anubis b/calexium_lib/web/CXM_making_a_web_site.anubis index e21833c..ade3d4e 100644 --- a/calexium_lib/web/CXM_making_a_web_site.anubis +++ b/calexium_lib/web/CXM_making_a_web_site.anubis @@ -1475,21 +1475,28 @@ public type HTML_Body: public type HTTP_Answer: - html_page(String title, - List(HTML_Meta) meta_tags, - List(CSS_Style) styles, - List(CSS_File) css_files, - List(JS_File) js_files, - HTML_Body body), - plain_text (String text), - custom_text(String mime_type, - String content), - custom_binary(String mime_type, - ByteArray content), - custom_tree(String mime_type, - Printable_tree content), - http_raw(Printable_tree), - html_content(HTML_Off_Form content). + html_page (HTTP_Status /*http_status*/, + String /*title*/, + List(HTML_Meta) /*meta_tags*/, + List(CSS_Style) /*styles*/, + List(CSS_File) /*css_files*/, + List(JS_File) /*js_files*/, + HTML_Body /*body*/), + plain_text (HTTP_Status /*http_status*/, + String /*text*/), + custom_text (HTTP_Status /*http_status*/, + String /*mime_type*/, + String /*content*/), + custom_binary(HTTP_Status /*http_status*/, + String /*mime_type*/, + ByteArray /*content*/), + custom_tree (HTTP_Status /*http_status*/, + String /*mime_type*/, + Printable_tree /*content*/), + http_raw (Printable_tree), + html_content (HTTP_Status /*http_status*/, + HTML_Off_Form). + public define HTTP_Answer html_page @@ -1498,7 +1505,7 @@ public define HTTP_Answer List(HTML_Meta) metas, HTML_Body body ) = - html_page(title,metas,[],[],[],body). + html_page(http_ok, title,metas,[],[],[],body). public define HTTP_Answer html_page @@ -1508,7 +1515,7 @@ public define HTTP_Answer List(CSS_Style) styles, HTML_Body body ) = - html_page(title, metas, styles, [], [], body). + html_page(http_ok, title, metas, styles, [], [], body). 'HTTP_Answer' represents the final product of the construction of a web page. @@ -4247,7 +4254,7 @@ define Printable_tree with ic_v = var((Int)0), if page is { - html_page(title,metas,css_styles, css_files, js_files, body) then + html_page(status, title, metas, css_styles, css_files, js_files, body) then if body is body(options,element) then with answer_body = [ doctype_w3c_header, @@ -4278,7 +4285,7 @@ define Printable_tree "\n", "" ], - [ "HTTP/1.1 200 OK", crlf, + [ "HTTP/1.1 " + format(status), crlf, format_headers(standard_headers), format_headers(standard_headers_for("text/html", length(answer_body), success(charset))), format_headers(additional_headers), @@ -4286,8 +4293,8 @@ define Printable_tree . answer_body ], - plain_text (String text) then - [ "HTTP/1.1 200 OK", crlf, + plain_text (HTTP_Status status, String text) then + [ "HTTP/1.1 " + format(status), crlf, format_headers(standard_headers), format_headers(standard_headers_for("text/plain", length(text), success(charset))), format_headers(additional_headers), @@ -4295,16 +4302,16 @@ define Printable_tree text . (Printable_tree)[] ], - custom_text(String mime_type, String content) then - [ "HTTP/1.1 200 OK", crlf, + custom_text(HTTP_Status status, String mime_type, String content) then + [ "HTTP/1.1 " + format(status), crlf, format_headers(standard_headers), format_headers(standard_headers_for(mime_type, length(content), success(charset))), format_headers(additional_headers), crlf, content . (Printable_tree)[] ], - custom_binary(String mime_type, ByteArray content) then - [ "HTTP/1.1 200 OK", crlf, + custom_binary(HTTP_Status status, String mime_type, ByteArray content) then + [ "HTTP/1.1 " + format(status), crlf, format_headers(standard_headers), format_headers(standard_headers_for(mime_type, length(content), failure)), format_headers(additional_headers), @@ -4312,8 +4319,8 @@ define Printable_tree content . (Printable_tree)[] ], - custom_tree(String mime_type, Printable_tree content) then - [ "HTTP/1.1 200 OK", crlf, + custom_tree(HTTP_Status status, String mime_type, Printable_tree content) then + [ "HTTP/1.1 " + format(status), crlf, format_headers(standard_headers), format_headers(standard_headers_for(mime_type, length(content), success(charset))), format_headers(additional_headers), @@ -4323,9 +4330,9 @@ define Printable_tree http_raw(Printable_tree content) then content, - html_content(HTML_Off_Form content_HTML) then + 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 200 OK", crlf, + [ "HTTP/1.1 " + format(status), crlf, format_headers(standard_headers), format_headers(standard_headers_for("text/html", length(content), success(charset))), format_headers(additional_headers), diff --git a/calexium_lib/web/CXM_multihost_http_server.anubis b/calexium_lib/web/CXM_multihost_http_server.anubis index 65e90b7..d2655b7 100644 --- a/calexium_lib/web/CXM_multihost_http_server.anubis +++ b/calexium_lib/web/CXM_multihost_http_server.anubis @@ -37,6 +37,7 @@ *** (7) Private download. *** (8) About web argument names. *** (9) A web dispatcher. + *** (10) HTTP Errors --------------------------------------------------------------------------------------- @@ -483,6 +484,61 @@ public define One ). + *** (10) HTTP Errors + +public type HTTP_Status: + http_continue, + http_switching_protocol, + + http_ok, + http_created, + http_accepted, + http_non_authoritative_info, + http_no_content, + http_reset_content, + http_partial_content, + + http_multiple_choices, + http_moved_permanently, + http_moved_temporarily, + http_see_other, + http_not_modified, + http_use_proxy, + http_temporary_redirect, + + http_bad_request, + http_unauthorized, + http_payment_required, + http_forbidden, + http_not_found, + http_method_not_allowed, + http_not_acceptable, + http_proxy_authentification_required, + http_request_timeout, + http_conflict, + http_gone, + http_length_required, + http_precondition_failed, + http_request_entity_too_large, + http_request_uri_too_long, + http_unsupported_media_type, + http_request_range_unsatisfiable, + http_expectation_failed, + + http_internal_server_error, + http_not_implemented, + http_bad_gateway, + http_service_unavailable, + http_gateway_timeout, + http_version_not_supported, + + http_error(Int /*code*/, String /*message*/). + +public define String + format + ( + HTTP_Status status + ). @@ -3863,3 +3919,59 @@ global define One +public define String + format + ( + HTTP_Status status + ) = + if status is + { + 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_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_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_error(code, message) then abs_to_decimal(code) + " " + message + }. + + -- libgit2 0.21.4