unicorn 0.7.0
[unicorn.git] / lib / unicorn / const.rb
blob3bd4808cdb285834107f2e7250c621f63c2b240e
2 module Unicorn
4   # Every standard HTTP code mapped to the appropriate message.  These are
5   # used so frequently that they are placed directly in Unicorn for easy
6   # access rather than Unicorn::Const itself.
7   HTTP_STATUS_CODES = {
8     100  => 'Continue',
9     101  => 'Switching Protocols',
10     200  => 'OK',
11     201  => 'Created',
12     202  => 'Accepted',
13     203  => 'Non-Authoritative Information',
14     204  => 'No Content',
15     205  => 'Reset Content',
16     206  => 'Partial Content',
17     300  => 'Multiple Choices',
18     301  => 'Moved Permanently',
19     302  => 'Moved Temporarily',
20     303  => 'See Other',
21     304  => 'Not Modified',
22     305  => 'Use Proxy',
23     400  => 'Bad Request',
24     401  => 'Unauthorized',
25     402  => 'Payment Required',
26     403  => 'Forbidden',
27     404  => 'Not Found',
28     405  => 'Method Not Allowed',
29     406  => 'Not Acceptable',
30     407  => 'Proxy Authentication Required',
31     408  => 'Request Time-out',
32     409  => 'Conflict',
33     410  => 'Gone',
34     411  => 'Length Required',
35     412  => 'Precondition Failed',
36     413  => 'Request Entity Too Large',
37     414  => 'Request-URI Too Large',
38     415  => 'Unsupported Media Type',
39     500  => 'Internal Server Error',
40     501  => 'Not Implemented',
41     502  => 'Bad Gateway',
42     503  => 'Service Unavailable',
43     504  => 'Gateway Time-out',
44     505  => 'HTTP Version not supported'
45   }.inject({}) { |hash,(code,msg)|
46       hash[code] = "#{code} #{msg}"
47       hash
48   }
50   # Frequently used constants when constructing requests or responses.  Many times
51   # the constant just refers to a string with the same contents.  Using these constants
52   # gave about a 3% to 10% performance improvement over using the strings directly.
53   # Symbols did not really improve things much compared to constants.
54   module Const
55     # This is the part of the path after the SCRIPT_NAME.
56     PATH_INFO="PATH_INFO".freeze
58     # The original URI requested by the client.
59     REQUEST_URI='REQUEST_URI'.freeze
60     REQUEST_PATH='REQUEST_PATH'.freeze
62     UNICORN_VERSION="0.7.0".freeze
64     DEFAULT_HOST = "0.0.0.0".freeze # default TCP listen host address
65     DEFAULT_PORT = "8080".freeze    # default TCP listen port
66     DEFAULT_LISTEN = "#{DEFAULT_HOST}:#{DEFAULT_PORT}".freeze
68     # The basic max request size we'll try to read.
69     CHUNK_SIZE=(16 * 1024)
71     # This is the maximum header that is allowed before a client is booted.  The parser detects
72     # this, but we'd also like to do this as well.
73     MAX_HEADER=1024 * (80 + 32)
75     # Maximum request body size before it is moved out of memory and into a tempfile for reading.
76     MAX_BODY=MAX_HEADER
78     # common errors we'll send back
79     ERROR_400_RESPONSE = "HTTP/1.1 400 Bad Request\r\n\r\n".freeze
80     ERROR_500_RESPONSE = "HTTP/1.1 500 Internal Server Error\r\n\r\n".freeze
82     # A frozen format for this is about 15% faster
83     CONTENT_LENGTH="CONTENT_LENGTH".freeze
84     REMOTE_ADDR="REMOTE_ADDR".freeze
85     HTTP_X_FORWARDED_FOR="HTTP_X_FORWARDED_FOR".freeze
86     RACK_INPUT="rack.input".freeze
87   end
89 end