| 
33823
 | 
     1  | 
(*  Title:      Tools/WWW_Find/http_status.ML
  | 
| 
33817
 | 
     2  | 
    Author:     Timothy Bourke, NICTA
  | 
| 
 | 
     3  | 
  | 
| 
 | 
     4  | 
HTTP status codes and reasons.
  | 
| 
 | 
     5  | 
*)
  | 
| 
33823
 | 
     6  | 
  | 
| 
33817
 | 
     7  | 
signature HTTP_STATUS =
  | 
| 
 | 
     8  | 
sig
  | 
| 
 | 
     9  | 
  type t
  | 
| 
 | 
    10  | 
  | 
| 
 | 
    11  | 
  val to_status_code : t -> int
  | 
| 
 | 
    12  | 
  val to_reason : t -> string
  | 
| 
 | 
    13  | 
  val from_status_code : int -> t option
  | 
| 
 | 
    14  | 
  | 
| 
 | 
    15  | 
  val continue : t
  | 
| 
 | 
    16  | 
  val switching_protocols : t
  | 
| 
 | 
    17  | 
  val ok : t
  | 
| 
 | 
    18  | 
  val created : t
  | 
| 
 | 
    19  | 
  val accepted : t
  | 
| 
 | 
    20  | 
  val non_authoritative_information : t
  | 
| 
 | 
    21  | 
  val no_content : t
  | 
| 
 | 
    22  | 
  val reset_content : t
  | 
| 
 | 
    23  | 
  val partial_content : t
  | 
| 
 | 
    24  | 
  val multiple_choices : t
  | 
| 
 | 
    25  | 
  val moved_permanently : t
  | 
| 
 | 
    26  | 
  val found : t
  | 
| 
 | 
    27  | 
  val see_other : t
  | 
| 
 | 
    28  | 
  val not_modified : t
  | 
| 
 | 
    29  | 
  val use_proxy : t
  | 
| 
 | 
    30  | 
  val temporary_redirect : t
  | 
| 
 | 
    31  | 
  val bad_request : t
  | 
| 
 | 
    32  | 
  val unauthorized : t
  | 
| 
 | 
    33  | 
  val payment_required : t
  | 
| 
 | 
    34  | 
  val forbidden : t
  | 
| 
 | 
    35  | 
  val not_found : t
  | 
| 
 | 
    36  | 
  val method_not_allowed : t
  | 
| 
 | 
    37  | 
  val not_acceptable : t
  | 
| 
 | 
    38  | 
  val proxy_authentication_required : t
  | 
| 
 | 
    39  | 
  val request_timeout : t
  | 
| 
 | 
    40  | 
  val conflict : t
  | 
| 
 | 
    41  | 
  val gone : t
  | 
| 
 | 
    42  | 
  val length_required : t
  | 
| 
 | 
    43  | 
  val precondition_failed : t
  | 
| 
 | 
    44  | 
  val request_entity_too_large : t
  | 
| 
 | 
    45  | 
  val request_uri_too_long : t
  | 
| 
 | 
    46  | 
  val unsupported_media_type : t
  | 
| 
 | 
    47  | 
  val requested_range_not_satisfiable : t
  | 
| 
 | 
    48  | 
  val expectation_failed : t
  | 
| 
 | 
    49  | 
  val internal_server_error : t
  | 
| 
 | 
    50  | 
  val not_implemented : t
  | 
| 
 | 
    51  | 
  val bad_gateway : t
  | 
| 
 | 
    52  | 
  val service_unavailable : t
  | 
| 
 | 
    53  | 
  val gateway_timeout : t
  | 
| 
 | 
    54  | 
  val http_version_not_supported : t
  | 
| 
 | 
    55  | 
  | 
| 
 | 
    56  | 
end;
  | 
| 
 | 
    57  | 
  | 
| 
 | 
    58  | 
structure HttpStatus : HTTP_STATUS =
  | 
| 
 | 
    59  | 
struct
  | 
| 
 | 
    60  | 
  | 
| 
 | 
    61  | 
type t = int
  | 
| 
 | 
    62  | 
  | 
| 
 | 
    63  | 
local
  | 
| 
 | 
    64  | 
val int_status_map = Inttab.make
  | 
| 
 | 
    65  | 
  [(100, "Continue"),
  | 
| 
 | 
    66  | 
   (101, "Switching Protocols"),
  | 
| 
 | 
    67  | 
   (200, "OK"),
  | 
| 
 | 
    68  | 
   (201, "Created"),
  | 
| 
 | 
    69  | 
   (202, "Accepted"),
  | 
| 
 | 
    70  | 
   (203, "Non-Authoritative Information"),
  | 
| 
 | 
    71  | 
   (204, "No Content"),
  | 
| 
 | 
    72  | 
   (205, "Reset Content"),
  | 
| 
 | 
    73  | 
   (206, "Partial Content"),
  | 
| 
 | 
    74  | 
   (300, "Multiple Choices"),
  | 
| 
 | 
    75  | 
   (301, "Moved Permanently"),
  | 
| 
 | 
    76  | 
   (302, "Found"),
  | 
| 
 | 
    77  | 
   (303, "See Other"),
  | 
| 
 | 
    78  | 
   (304, "Not Modified"),
  | 
| 
 | 
    79  | 
   (305, "Use Proxy"),
  | 
| 
 | 
    80  | 
   (307, "Temporary Redirect"),
  | 
| 
 | 
    81  | 
   (400, "Bad Request"),
  | 
| 
 | 
    82  | 
   (401, "Unauthorized"),
  | 
| 
 | 
    83  | 
   (402, "Payment Required"),
  | 
| 
 | 
    84  | 
   (403, "Forbidden"),
  | 
| 
 | 
    85  | 
   (404, "Not Found"),
  | 
| 
 | 
    86  | 
   (405, "Method Not Allowed"),
  | 
| 
 | 
    87  | 
   (406, "Not Acceptable"),
  | 
| 
 | 
    88  | 
   (407, "Proxy Authentication Required"),
  | 
| 
 | 
    89  | 
   (408, "Request Timeout"),
  | 
| 
 | 
    90  | 
   (409, "Conflict"),
  | 
| 
 | 
    91  | 
   (410, "Gone"),
  | 
| 
 | 
    92  | 
   (411, "Length Required"),
  | 
| 
 | 
    93  | 
   (412, "Precondition Failed"),
  | 
| 
 | 
    94  | 
   (413, "Request Entity Too Large"),
  | 
| 
 | 
    95  | 
   (414, "Request URI Too Long"),
  | 
| 
 | 
    96  | 
   (415, "Unsupported Media Type"),
  | 
| 
 | 
    97  | 
   (416, "Requested Range Not Satisfiable"),
  | 
| 
 | 
    98  | 
   (417, "Expectation Failed"),
  | 
| 
 | 
    99  | 
   (500, "Internal Server Error"),
  | 
| 
 | 
   100  | 
   (501, "Not Implemented"),
  | 
| 
 | 
   101  | 
   (502, "Bad Gateway"),
  | 
| 
 | 
   102  | 
   (503, "Service Unavailable"),
  | 
| 
 | 
   103  | 
   (504, "Gateway Timeout"),
  | 
| 
 | 
   104  | 
   (505, "HTTP Version Not Supported")];
  | 
| 
 | 
   105  | 
in
  | 
| 
 | 
   106  | 
fun from_status_code i =
  | 
| 
 | 
   107  | 
  if is_some (Inttab.lookup int_status_map i)
  | 
| 
 | 
   108  | 
  then SOME i
  | 
| 
 | 
   109  | 
  else NONE;
  | 
| 
 | 
   110  | 
  | 
| 
 | 
   111  | 
val to_reason = the o Inttab.lookup int_status_map;
  | 
| 
 | 
   112  | 
end;
  | 
| 
 | 
   113  | 
  | 
| 
 | 
   114  | 
val to_status_code = I;
  | 
| 
 | 
   115  | 
  | 
| 
 | 
   116  | 
val continue = 100;
  | 
| 
 | 
   117  | 
val switching_protocols = 101;
  | 
| 
 | 
   118  | 
val ok = 200;
  | 
| 
 | 
   119  | 
val created = 201;
  | 
| 
 | 
   120  | 
val accepted = 202;
  | 
| 
 | 
   121  | 
val non_authoritative_information = 203;
  | 
| 
 | 
   122  | 
val no_content = 204;
  | 
| 
 | 
   123  | 
val reset_content = 205;
  | 
| 
 | 
   124  | 
val partial_content = 206;
  | 
| 
 | 
   125  | 
val multiple_choices = 300;
  | 
| 
 | 
   126  | 
val moved_permanently = 301;
  | 
| 
 | 
   127  | 
val found = 302;
  | 
| 
 | 
   128  | 
val see_other = 303;
  | 
| 
 | 
   129  | 
val not_modified = 304;
  | 
| 
 | 
   130  | 
val use_proxy = 305;
  | 
| 
 | 
   131  | 
val temporary_redirect = 307;
  | 
| 
 | 
   132  | 
val bad_request = 400;
  | 
| 
 | 
   133  | 
val unauthorized = 401;
  | 
| 
 | 
   134  | 
val payment_required = 402;
  | 
| 
 | 
   135  | 
val forbidden = 403;
  | 
| 
 | 
   136  | 
val not_found = 404;
  | 
| 
 | 
   137  | 
val method_not_allowed = 405;
  | 
| 
 | 
   138  | 
val not_acceptable = 406;
  | 
| 
 | 
   139  | 
val proxy_authentication_required = 407;
  | 
| 
 | 
   140  | 
val request_timeout = 408;
  | 
| 
 | 
   141  | 
val conflict = 409;
  | 
| 
 | 
   142  | 
val gone = 410;
  | 
| 
 | 
   143  | 
val length_required = 411;
  | 
| 
 | 
   144  | 
val precondition_failed = 412;
  | 
| 
 | 
   145  | 
val request_entity_too_large = 413;
  | 
| 
 | 
   146  | 
val request_uri_too_long = 414;
  | 
| 
 | 
   147  | 
val unsupported_media_type = 415;
  | 
| 
 | 
   148  | 
val requested_range_not_satisfiable = 416;
  | 
| 
 | 
   149  | 
val expectation_failed = 417;
  | 
| 
 | 
   150  | 
val internal_server_error = 500;
  | 
| 
 | 
   151  | 
val not_implemented = 501;
  | 
| 
 | 
   152  | 
val bad_gateway = 502;
  | 
| 
 | 
   153  | 
val service_unavailable = 503;
  | 
| 
 | 
   154  | 
val gateway_timeout = 504;
  | 
| 
 | 
   155  | 
val http_version_not_supported = 505;
  | 
| 
 | 
   156  | 
  | 
| 
 | 
   157  | 
end;
  | 
| 
 | 
   158  | 
  |