Commit 23f86e1ba365bedc9aaa4f239bb257f4326615e2

Authored by Cédric RICARD
1 parent a9d7f5e7

Added HTTP error codes

calexium_lib/web/CXM_making_a_web_site.anubis
@@ -1475,21 +1475,28 @@ public type HTML_Body: @@ -1475,21 +1475,28 @@ public type HTML_Body:
1475 1475
1476 1476
1477 public type HTTP_Answer: 1477 public type HTTP_Answer:
1478 - html_page(String title,  
1479 - List(HTML_Meta) meta_tags,  
1480 - List(CSS_Style) styles,  
1481 - List(CSS_File) css_files,  
1482 - List(JS_File) js_files,  
1483 - HTML_Body body),  
1484 - plain_text (String text),  
1485 - custom_text(String mime_type,  
1486 - String content),  
1487 - custom_binary(String mime_type,  
1488 - ByteArray content),  
1489 - custom_tree(String mime_type,  
1490 - Printable_tree content),  
1491 - http_raw(Printable_tree),  
1492 - html_content(HTML_Off_Form content). 1478 + html_page (HTTP_Status /*http_status*/,
  1479 + String /*title*/,
  1480 + List(HTML_Meta) /*meta_tags*/,
  1481 + List(CSS_Style) /*styles*/,
  1482 + List(CSS_File) /*css_files*/,
  1483 + List(JS_File) /*js_files*/,
  1484 + HTML_Body /*body*/),
  1485 + plain_text (HTTP_Status /*http_status*/,
  1486 + String /*text*/),
  1487 + custom_text (HTTP_Status /*http_status*/,
  1488 + String /*mime_type*/,
  1489 + String /*content*/),
  1490 + custom_binary(HTTP_Status /*http_status*/,
  1491 + String /*mime_type*/,
  1492 + ByteArray /*content*/),
  1493 + custom_tree (HTTP_Status /*http_status*/,
  1494 + String /*mime_type*/,
  1495 + Printable_tree /*content*/),
  1496 + http_raw (Printable_tree),
  1497 + html_content (HTTP_Status /*http_status*/,
  1498 + HTML_Off_Form).
  1499 +
1493 1500
1494 public define HTTP_Answer 1501 public define HTTP_Answer
1495 html_page 1502 html_page
@@ -1498,7 +1505,7 @@ public define HTTP_Answer @@ -1498,7 +1505,7 @@ public define HTTP_Answer
1498 List(HTML_Meta) metas, 1505 List(HTML_Meta) metas,
1499 HTML_Body body 1506 HTML_Body body
1500 ) = 1507 ) =
1501 - html_page(title,metas,[],[],[],body). 1508 + html_page(http_ok, title,metas,[],[],[],body).
1502 1509
1503 public define HTTP_Answer 1510 public define HTTP_Answer
1504 html_page 1511 html_page
@@ -1508,7 +1515,7 @@ public define HTTP_Answer @@ -1508,7 +1515,7 @@ public define HTTP_Answer
1508 List(CSS_Style) styles, 1515 List(CSS_Style) styles,
1509 HTML_Body body 1516 HTML_Body body
1510 ) = 1517 ) =
1511 - html_page(title, metas, styles, [], [], body). 1518 + html_page(http_ok, title, metas, styles, [], [], body).
1512 1519
1513 'HTTP_Answer' represents the final product of the construction of a web page. 1520 'HTTP_Answer' represents the final product of the construction of a web page.
1514 1521
@@ -4247,7 +4254,7 @@ define Printable_tree @@ -4247,7 +4254,7 @@ define Printable_tree
4247 with ic_v = var((Int)0), 4254 with ic_v = var((Int)0),
4248 if page is 4255 if page is
4249 { 4256 {
4250 - html_page(title,metas,css_styles, css_files, js_files, body) then 4257 + html_page(status, title, metas, css_styles, css_files, js_files, body) then
4251 if body is body(options,element) then 4258 if body is body(options,element) then
4252 with answer_body = 4259 with answer_body =
4253 [ doctype_w3c_header, 4260 [ doctype_w3c_header,
@@ -4278,7 +4285,7 @@ define Printable_tree @@ -4278,7 +4285,7 @@ define Printable_tree
4278 "</body>\n", 4285 "</body>\n",
4279 "</html>" 4286 "</html>"
4280 ], 4287 ],
4281 - [ "HTTP/1.1 200 OK", crlf, 4288 + [ "HTTP/1.1 " + format(status), crlf,
4282 format_headers(standard_headers), 4289 format_headers(standard_headers),
4283 format_headers(standard_headers_for("text/html", length(answer_body), success(charset))), 4290 format_headers(standard_headers_for("text/html", length(answer_body), success(charset))),
4284 format_headers(additional_headers), 4291 format_headers(additional_headers),
@@ -4286,8 +4293,8 @@ define Printable_tree @@ -4286,8 +4293,8 @@ define Printable_tree
4286 . answer_body 4293 . answer_body
4287 ], 4294 ],
4288 4295
4289 - plain_text (String text) then  
4290 - [ "HTTP/1.1 200 OK", crlf, 4296 + plain_text (HTTP_Status status, String text) then
  4297 + [ "HTTP/1.1 " + format(status), crlf,
4291 format_headers(standard_headers), 4298 format_headers(standard_headers),
4292 format_headers(standard_headers_for("text/plain", length(text), success(charset))), 4299 format_headers(standard_headers_for("text/plain", length(text), success(charset))),
4293 format_headers(additional_headers), 4300 format_headers(additional_headers),
@@ -4295,16 +4302,16 @@ define Printable_tree @@ -4295,16 +4302,16 @@ define Printable_tree
4295 text . (Printable_tree)[] 4302 text . (Printable_tree)[]
4296 ], 4303 ],
4297 4304
4298 - custom_text(String mime_type, String content) then  
4299 - [ "HTTP/1.1 200 OK", crlf, 4305 + custom_text(HTTP_Status status, String mime_type, String content) then
  4306 + [ "HTTP/1.1 " + format(status), crlf,
4300 format_headers(standard_headers), 4307 format_headers(standard_headers),
4301 format_headers(standard_headers_for(mime_type, length(content), success(charset))), 4308 format_headers(standard_headers_for(mime_type, length(content), success(charset))),
4302 format_headers(additional_headers), 4309 format_headers(additional_headers),
4303 crlf, 4310 crlf,
4304 content . (Printable_tree)[] 4311 content . (Printable_tree)[]
4305 ], 4312 ],
4306 - custom_binary(String mime_type, ByteArray content) then  
4307 - [ "HTTP/1.1 200 OK", crlf, 4313 + custom_binary(HTTP_Status status, String mime_type, ByteArray content) then
  4314 + [ "HTTP/1.1 " + format(status), crlf,
4308 format_headers(standard_headers), 4315 format_headers(standard_headers),
4309 format_headers(standard_headers_for(mime_type, length(content), failure)), 4316 format_headers(standard_headers_for(mime_type, length(content), failure)),
4310 format_headers(additional_headers), 4317 format_headers(additional_headers),
@@ -4312,8 +4319,8 @@ define Printable_tree @@ -4312,8 +4319,8 @@ define Printable_tree
4312 content . (Printable_tree)[] 4319 content . (Printable_tree)[]
4313 ], 4320 ],
4314 4321
4315 - custom_tree(String mime_type, Printable_tree content) then  
4316 - [ "HTTP/1.1 200 OK", crlf, 4322 + custom_tree(HTTP_Status status, String mime_type, Printable_tree content) then
  4323 + [ "HTTP/1.1 " + format(status), crlf,
4317 format_headers(standard_headers), 4324 format_headers(standard_headers),
4318 format_headers(standard_headers_for(mime_type, length(content), success(charset))), 4325 format_headers(standard_headers_for(mime_type, length(content), success(charset))),
4319 format_headers(additional_headers), 4326 format_headers(additional_headers),
@@ -4323,9 +4330,9 @@ define Printable_tree @@ -4323,9 +4330,9 @@ define Printable_tree
4323 4330
4324 http_raw(Printable_tree content) then content, 4331 http_raw(Printable_tree content) then content,
4325 4332
4326 - html_content(HTML_Off_Form content_HTML) then 4333 + html_content(HTTP_Status status, HTML_Off_Form content_HTML) then
4327 with content = format(cinfo, state_name, ic_v, content_HTML, is_https), 4334 with content = format(cinfo, state_name, ic_v, content_HTML, is_https),
4328 - [ "HTTP/1.1 200 OK", crlf, 4335 + [ "HTTP/1.1 " + format(status), crlf,
4329 format_headers(standard_headers), 4336 format_headers(standard_headers),
4330 format_headers(standard_headers_for("text/html", length(content), success(charset))), 4337 format_headers(standard_headers_for("text/html", length(content), success(charset))),
4331 format_headers(additional_headers), 4338 format_headers(additional_headers),
calexium_lib/web/CXM_multihost_http_server.anubis
@@ -37,6 +37,7 @@ @@ -37,6 +37,7 @@
37 *** (7) Private download. 37 *** (7) Private download.
38 *** (8) About web argument names. 38 *** (8) About web argument names.
39 *** (9) A web dispatcher. 39 *** (9) A web dispatcher.
  40 + *** (10) HTTP Errors
40 41
41 --------------------------------------------------------------------------------------- 42 ---------------------------------------------------------------------------------------
42 43
@@ -483,6 +484,61 @@ public define One @@ -483,6 +484,61 @@ public define One
483 ). 484 ).
484 485
485 486
  487 + *** (10) HTTP Errors
  488 +
  489 +public type HTTP_Status:
  490 + http_continue,
  491 + http_switching_protocol,
  492 +
  493 + http_ok,
  494 + http_created,
  495 + http_accepted,
  496 + http_non_authoritative_info,
  497 + http_no_content,
  498 + http_reset_content,
  499 + http_partial_content,
  500 +
  501 + http_multiple_choices,
  502 + http_moved_permanently,
  503 + http_moved_temporarily,
  504 + http_see_other,
  505 + http_not_modified,
  506 + http_use_proxy,
  507 + http_temporary_redirect,
  508 +
  509 + http_bad_request,
  510 + http_unauthorized,
  511 + http_payment_required,
  512 + http_forbidden,
  513 + http_not_found,
  514 + http_method_not_allowed,
  515 + http_not_acceptable,
  516 + http_proxy_authentification_required,
  517 + http_request_timeout,
  518 + http_conflict,
  519 + http_gone,
  520 + http_length_required,
  521 + http_precondition_failed,
  522 + http_request_entity_too_large,
  523 + http_request_uri_too_long,
  524 + http_unsupported_media_type,
  525 + http_request_range_unsatisfiable,
  526 + http_expectation_failed,
  527 +
  528 + http_internal_server_error,
  529 + http_not_implemented,
  530 + http_bad_gateway,
  531 + http_service_unavailable,
  532 + http_gateway_timeout,
  533 + http_version_not_supported,
  534 +
  535 + http_error(Int /*code*/, String /*message*/).
  536 +
  537 +public define String
  538 + format
  539 + (
  540 + HTTP_Status status
  541 + ).
486 542
487 543
488 544
@@ -3863,3 +3919,59 @@ global define One @@ -3863,3 +3919,59 @@ global define One
3863 3919
3864 3920
3865 3921
  3922 +public define String
  3923 + format
  3924 + (
  3925 + HTTP_Status status
  3926 + ) =
  3927 + if status is
  3928 + {
  3929 + http_continue then "100 Continue",
  3930 + http_switching_protocol then "101 Switching Protocols",
  3931 +
  3932 + http_ok then "200 OK",
  3933 + http_created then "201 Created",
  3934 + http_accepted then "202 Accepted",
  3935 + http_non_authoritative_info then "203 Non-Authoritative Information",
  3936 + http_no_content then "204 No Content",
  3937 + http_reset_content then "205 Reset Content",
  3938 + http_partial_content then "206 Partial Content",
  3939 +
  3940 + http_multiple_choices then "300 Multiple Choices",
  3941 + http_moved_permanently then "301 Moved Permanently",
  3942 + http_moved_temporarily then "302 Moved Temporarily",
  3943 + http_see_other then "303 See Other",
  3944 + http_not_modified then "304 Not Modified",
  3945 + http_use_proxy then "305 Use Proxy",
  3946 + http_temporary_redirect then "307 Temporary Redirect",
  3947 +
  3948 + http_bad_request then "400 Bad Request",
  3949 + http_unauthorized then "401 Unauthorized",
  3950 + http_payment_required then "402 Payment Required",
  3951 + http_forbidden then "403 Forbidden",
  3952 + http_not_found then "404 Not Found",
  3953 + http_method_not_allowed then "405 Method Not Allowed",
  3954 + http_not_acceptable then "406 Not Acceptable",
  3955 + http_proxy_authentification_required then "407 Proxy Authentication Required",
  3956 + http_request_timeout then "408 Request Time-out",
  3957 + http_conflict then "409 Conflict",
  3958 + http_gone then "410 Gone",
  3959 + http_length_required then "411 Length Required",
  3960 + http_precondition_failed then "412 Precondition Failed",
  3961 + http_request_entity_too_large then "413 Request Entity Too Large",
  3962 + http_request_uri_too_long then "414 Request-URI Too Long",
  3963 + http_unsupported_media_type then "415 Unsupported Media Type",
  3964 + http_request_range_unsatisfiable then "416 Requested range unsatisfiable",
  3965 + http_expectation_failed then "417 Expectation failed",
  3966 +
  3967 + http_internal_server_error then "500 Internal Server Error",
  3968 + http_not_implemented then "501 Not Implemented",
  3969 + http_bad_gateway then "502 Bad Gateway",
  3970 + http_service_unavailable then "503 Service Unavailable",
  3971 + http_gateway_timeout then "504 Gateway Time-out",
  3972 + http_version_not_supported then "505 HTTP Version not supported",
  3973 +
  3974 + http_error(code, message) then abs_to_decimal(code) + " " + message
  3975 + }.
  3976 +
  3977 +