File: http-status.rb

package info (click to toggle)
whatweb 0.6.1-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 23,948 kB
  • sloc: ruby: 43,493; sh: 213; makefile: 41
file content (111 lines) | stat: -rw-r--r-- 3,254 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Copyright 2009 to 2025 Andrew Horton and Brendan Coles
#
# This file is part of WhatWeb.
#
# WhatWeb is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# at your option) any later version.
#
# WhatWeb is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with WhatWeb.  If not, see <http://www.gnu.org/licenses/>.

class HTTP_Status
  # return HTTP status code as a string
  def self.code(number)
    number = number.to_s

    abort('HTTP_Status must be initialized') unless @status_codes

    if @status_codes[number]
      @status_codes[number]
    else
      'Unassigned'
    end
  end

  # Status code list from:
  # https://raw.githubusercontent.com/Mr-Pi/httpStatusCodes/master/priv/http-status-codes-1.csv
  def self.initialize
    @status_codes = {}

    text = "
100,Continue,[RFC2616]
101,Switching Protocols,[RFC2616]
102,Processing,[RFC2518]
103-199,Unassigned,
200,OK,[RFC2616]
201,Created,[RFC2616]
202,Accepted,[RFC2616]
203,Non-Authoritative Information,[RFC2616]
204,No Content,[RFC2616]
205,Reset Content,[RFC2616]
206,Partial Content,[RFC2616]
207,Multi-Status,[RFC4918]
208,Already Reported,[RFC5842]
209-225,Unassigned,
226,IM Used,[RFC3229]
227-299,Unassigned,
300,Multiple Choices,[RFC2616]
301,Moved Permanently,[RFC2616]
302,Found,[RFC2616]
303,See Other,[RFC2616]
304,Not Modified,[RFC2616]
305,Use Proxy,[RFC2616]
306,Reserved,[RFC2616]
307,Temporary Redirect,[RFC2616]
308,Permanent Redirect,[RFC-reschke-http-status-308-07]
309-399,Unassigned,
400,Bad Request,[RFC2616]
401,Unauthorized,[RFC2616]
402,Payment Required,[RFC2616]
403,Forbidden,[RFC2616]
404,Not Found,[RFC2616]
405,Method Not Allowed,[RFC2616]
406,Not Acceptable,[RFC2616]
407,Proxy Authentication Required,[RFC2616]
408,Request Timeout,[RFC2616]
409,Conflict,[RFC2616]
410,Gone,[RFC2616]
411,Length Required,[RFC2616]
412,Precondition Failed,[RFC2616]
413,Request Entity Too Large,[RFC2616]
414,Request-URI Too Long,[RFC2616]
415,Unsupported Media Type,[RFC2616]
416,Requested Range Not Satisfiable,[RFC2616]
417,Expectation Failed,[RFC2616]
422,Unprocessable Entity,[RFC4918]
423,Locked,[RFC4918]
424,Failed Dependency,[RFC4918]
425,Unassigned,
426,Upgrade Required,[RFC2817]
427,Unassigned,
428,Precondition Required,[RFC6585]
429,Too Many Requests,[RFC6585]
430,Unassigned,
431,Request Header Fields Too Large,[RFC6585]
432-499,Unassigned,
500,Internal Server Error,[RFC2616]
501,Not Implemented,[RFC2616]
502,Bad Gateway,[RFC2616]
503,Service Unavailable,[RFC2616]
504,Gateway Timeout,[RFC2616]
505,HTTP Version Not Supported,[RFC2616]
506,Variant Also Negotiates (Experimental),[RFC2295]
507,Insufficient Storage,[RFC4918]
508,Loop Detected,[RFC5842]
509,Unassigned,
510,Not Extended,[RFC2774]
511,Network Authentication Required,[RFC6585]
512-599,Unassigned,
"
    text.scan(/^([0-9]+),([^,]+)/).each do |k, v|
      @status_codes[k] = v
    end
  end
end