Skip to content

Commit f026c47

Browse files
ujifgcMartin Verzilli
authored and
Martin Verzilli
committedJun 15, 2017
update HTTP.default_status_message_for to use official IANA Registry
1 parent 11e76e4 commit f026c47

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed
 

‎spec/std/http/http_spec.cr

+10
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,14 @@ describe HTTP do
8585
end
8686
end
8787
end
88+
89+
describe ".default_status_message_for" do
90+
it "returns a default message for status 200" do
91+
HTTP.default_status_message_for(200).should eq("OK")
92+
end
93+
94+
it "returns an empty string on non-existent status" do
95+
HTTP.default_status_message_for(0).should eq("")
96+
end
97+
end
8898
end

‎src/http/common.cr

+28-17
Original file line numberDiff line numberDiff line change
@@ -300,20 +300,33 @@ module HTTP
300300
end
301301

302302
# Returns the default status message of the given HTTP status code.
303+
#
304+
# Based on [Hypertext Transfer Protocol (HTTP) Status Code Registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml)
305+
#
306+
# Last Updated 2017-04-14
307+
#
308+
# HTTP Status Codes (source: [http-status-codes-1.csv](https://www.iana.org/assignments/http-status-codes/http-status-codes-1.csv))
309+
#
310+
# * 1xx: Informational - Request received, continuing process
311+
# * 2xx: Success - The action was successfully received, understood, and accepted
312+
# * 3xx: Redirection - Further action must be taken in order to complete the request
313+
# * 4xx: Client Error - The request contains bad syntax or cannot be fulfilled
314+
# * 5xx: Server Error - The server failed to fulfill an apparently valid request
315+
#
303316
def self.default_status_message_for(status_code : Int) : String
304317
case status_code
305318
when 100 then "Continue"
306319
when 101 then "Switching Protocols"
307-
when 102 then "Processing" # RFC 2518 (WebDAV)
320+
when 102 then "Processing"
308321
when 200 then "OK"
309322
when 201 then "Created"
310323
when 202 then "Accepted"
311324
when 203 then "Non-Authoritative Information"
312325
when 204 then "No Content"
313326
when 205 then "Reset Content"
314327
when 206 then "Partial Content"
315-
when 207 then "Multi-Status" # RFC 2518 (WebDAV)
316-
when 208 then "Already Reported" # RFC 5842
328+
when 207 then "Multi-Status"
329+
when 208 then "Already Reported"
317330
when 226 then "IM Used"
318331
when 300 then "Multiple Choices"
319332
when 301 then "Moved Permanently"
@@ -322,7 +335,7 @@ module HTTP
322335
when 304 then "Not Modified"
323336
when 305 then "Use Proxy"
324337
when 307 then "Temporary Redirect"
325-
when 308 then "Permanent Redirect" # RFC 7238
338+
when 308 then "Permanent Redirect"
326339
when 400 then "Bad Request"
327340
when 401 then "Unauthorized"
328341
when 402 then "Payment Required"
@@ -336,32 +349,30 @@ module HTTP
336349
when 410 then "Gone"
337350
when 411 then "Length Required"
338351
when 412 then "Precondition Failed"
339-
when 413 then "Request Entity Too Large"
340-
when 414 then "Request-URI Too Long"
352+
when 413 then "Payload Too Large"
353+
when 414 then "URI Too Long"
341354
when 415 then "Unsupported Media Type"
342-
when 416 then "Requested Range Not Satisfiable"
355+
when 416 then "Range Not Satisfiable"
343356
when 417 then "Expectation Failed"
344-
when 418 then "I'm a teapot" # RFC 2324
345357
when 421 then "Misdirected Request"
346-
when 422 then "Unprocessable Entity" # RFC 2518 (WebDAV)
347-
when 423 then "Locked" # RFC 2518 (WebDAV)
348-
when 424 then "Failed Dependency" # RFC 2518 (WebDAV)
349-
when 426 then "Upgrade Required" # RFC 2817
358+
when 422 then "Unprocessable Entity"
359+
when 423 then "Locked"
360+
when 424 then "Failed Dependency"
361+
when 426 then "Upgrade Required"
350362
when 428 then "Precondition Required"
351363
when 429 then "Too Many Requests"
352364
when 431 then "Request Header Fields Too Large"
353-
when 449 then "Retry With" # unofficial Microsoft
354365
when 451 then "Unavailable For Legal Reasons"
355366
when 500 then "Internal Server Error"
356367
when 501 then "Not Implemented"
357368
when 502 then "Bad Gateway"
358369
when 503 then "Service Unavailable"
359370
when 504 then "Gateway Timeout"
360371
when 505 then "HTTP Version Not Supported"
361-
when 506 then "Variant Also Negotiates" # RFC 2295
362-
when 507 then "Insufficient Storage" # RFC 2518 (WebDAV)
363-
when 509 then "Bandwidth Limit Exceeded" # unofficial
364-
when 510 then "Not Extended" # RFC 2774
372+
when 506 then "Variant Also Negotiates"
373+
when 507 then "Insufficient Storage"
374+
when 508 then "Loop Detected"
375+
when 510 then "Not Extended"
365376
when 511 then "Network Authentication Required"
366377
else ""
367378
end

0 commit comments

Comments
 (0)
Please sign in to comment.