2016-03-06 07:51:18 -05:00
|
|
|
#encoding: utf-8
|
2018-09-17 12:41:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2011-09-22 22:24:43 -04:00
|
|
|
module Puma
|
2012-09-10 20:14:35 -04:00
|
|
|
class UnsupportedOption < RuntimeError
|
|
|
|
end
|
|
|
|
|
2007-10-26 05:23:10 -04:00
|
|
|
|
|
|
|
# Every standard HTTP code mapped to the appropriate message. These are
|
2011-09-22 22:24:43 -04:00
|
|
|
# used so frequently that they are placed directly in Puma for easy
|
|
|
|
# access rather than Puma::Const itself.
|
2015-07-14 13:28:59 -04:00
|
|
|
|
|
|
|
# Every standard HTTP code mapped to the appropriate message.
|
|
|
|
# Generated with:
|
|
|
|
# curl -s https://www.iana.org/assignments/http-status-codes/http-status-codes-1.csv | \
|
|
|
|
# ruby -ne 'm = /^(\d{3}),(?!Unassigned|\(Unused\))([^,]+)/.match($_) and \
|
|
|
|
# puts "#{m[1]} => \x27#{m[2].strip}\x27,"'
|
|
|
|
HTTP_STATUS_CODES = {
|
|
|
|
100 => 'Continue',
|
|
|
|
101 => 'Switching Protocols',
|
|
|
|
102 => 'Processing',
|
|
|
|
200 => 'OK',
|
|
|
|
201 => 'Created',
|
|
|
|
202 => 'Accepted',
|
|
|
|
203 => 'Non-Authoritative Information',
|
|
|
|
204 => 'No Content',
|
|
|
|
205 => 'Reset Content',
|
|
|
|
206 => 'Partial Content',
|
|
|
|
207 => 'Multi-Status',
|
|
|
|
208 => 'Already Reported',
|
|
|
|
226 => 'IM Used',
|
|
|
|
300 => 'Multiple Choices',
|
|
|
|
301 => 'Moved Permanently',
|
|
|
|
302 => 'Found',
|
|
|
|
303 => 'See Other',
|
|
|
|
304 => 'Not Modified',
|
|
|
|
305 => 'Use Proxy',
|
|
|
|
307 => 'Temporary Redirect',
|
|
|
|
308 => 'Permanent Redirect',
|
|
|
|
400 => 'Bad Request',
|
|
|
|
401 => 'Unauthorized',
|
|
|
|
402 => 'Payment Required',
|
|
|
|
403 => 'Forbidden',
|
|
|
|
404 => 'Not Found',
|
|
|
|
405 => 'Method Not Allowed',
|
|
|
|
406 => 'Not Acceptable',
|
|
|
|
407 => 'Proxy Authentication Required',
|
|
|
|
408 => 'Request Timeout',
|
|
|
|
409 => 'Conflict',
|
|
|
|
410 => 'Gone',
|
|
|
|
411 => 'Length Required',
|
|
|
|
412 => 'Precondition Failed',
|
|
|
|
413 => 'Payload Too Large',
|
|
|
|
414 => 'URI Too Long',
|
|
|
|
415 => 'Unsupported Media Type',
|
|
|
|
416 => 'Range Not Satisfiable',
|
|
|
|
417 => 'Expectation Failed',
|
2017-08-11 09:46:13 -04:00
|
|
|
418 => 'I\'m A Teapot',
|
2017-10-11 10:10:24 -04:00
|
|
|
421 => 'Misdirected Request',
|
2015-07-14 13:28:59 -04:00
|
|
|
422 => 'Unprocessable Entity',
|
|
|
|
423 => 'Locked',
|
|
|
|
424 => 'Failed Dependency',
|
|
|
|
426 => 'Upgrade Required',
|
|
|
|
428 => 'Precondition Required',
|
|
|
|
429 => 'Too Many Requests',
|
|
|
|
431 => 'Request Header Fields Too Large',
|
2017-10-11 10:10:24 -04:00
|
|
|
451 => 'Unavailable For Legal Reasons',
|
2015-07-14 13:28:59 -04:00
|
|
|
500 => 'Internal Server Error',
|
|
|
|
501 => 'Not Implemented',
|
|
|
|
502 => 'Bad Gateway',
|
|
|
|
503 => 'Service Unavailable',
|
|
|
|
504 => 'Gateway Timeout',
|
|
|
|
505 => 'HTTP Version Not Supported',
|
|
|
|
506 => 'Variant Also Negotiates',
|
|
|
|
507 => 'Insufficient Storage',
|
|
|
|
508 => 'Loop Detected',
|
|
|
|
510 => 'Not Extended',
|
|
|
|
511 => 'Network Authentication Required'
|
|
|
|
}
|
|
|
|
|
2011-12-13 08:45:12 -05:00
|
|
|
# For some HTTP status codes the client only expects headers.
|
2015-07-14 13:28:59 -04:00
|
|
|
#
|
|
|
|
|
2016-08-31 15:34:06 -04:00
|
|
|
STATUS_WITH_NO_ENTITY_BODY = {
|
|
|
|
204 => true,
|
|
|
|
205 => true,
|
|
|
|
304 => true
|
|
|
|
}
|
2011-12-13 08:45:12 -05:00
|
|
|
|
2007-10-26 05:23:10 -04:00
|
|
|
# Frequently used constants when constructing requests or responses. Many times
|
|
|
|
# the constant just refers to a string with the same contents. Using these constants
|
|
|
|
# gave about a 3% to 10% performance improvement over using the strings directly.
|
2011-09-24 00:01:03 -04:00
|
|
|
#
|
|
|
|
# The constants are frozen because Hash#[]= when called with a String key dups
|
|
|
|
# the String UNLESS the String is frozen. This saves us therefore 2 object
|
|
|
|
# allocations when creating the env hash later.
|
2007-10-26 05:23:10 -04:00
|
|
|
#
|
2011-09-22 22:24:43 -04:00
|
|
|
# While Puma does try to emulate the CGI/1.2 protocol, it does not use the REMOTE_IDENT,
|
2010-07-24 13:04:37 -04:00
|
|
|
# REMOTE_USER, or REMOTE_HOST parameters since those are either a security problem or
|
2007-10-26 05:23:10 -04:00
|
|
|
# too taxing on performance.
|
|
|
|
module Const
|
2011-10-05 00:11:10 -04:00
|
|
|
|
2019-01-08 17:36:05 -05:00
|
|
|
PUMA_VERSION = VERSION = "3.12.1".freeze
|
2018-07-13 11:08:56 -04:00
|
|
|
CODE_NAME = "Llamas in Pajamas".freeze
|
2016-02-27 12:32:18 -05:00
|
|
|
PUMA_SERVER_STRING = ['puma', PUMA_VERSION, CODE_NAME].join(' ').freeze
|
2016-08-31 15:47:42 -04:00
|
|
|
|
2012-08-10 20:02:30 -04:00
|
|
|
FAST_TRACK_KA_TIMEOUT = 0.2
|
|
|
|
|
2011-10-05 00:11:10 -04:00
|
|
|
# The default number of seconds for another request within a persistent
|
|
|
|
# session.
|
|
|
|
PERSISTENT_TIMEOUT = 20
|
|
|
|
|
2012-08-09 19:54:55 -04:00
|
|
|
# The default number of seconds to wait until we get the first data
|
|
|
|
# for the request
|
|
|
|
FIRST_DATA_TIMEOUT = 30
|
|
|
|
|
2014-02-04 11:46:13 -05:00
|
|
|
# How long to wait when getting some write blocking on the socket when
|
|
|
|
# sending data back
|
|
|
|
WRITE_TIMEOUT = 10
|
|
|
|
|
2011-09-24 00:01:03 -04:00
|
|
|
# The original URI requested by the client.
|
|
|
|
REQUEST_URI= 'REQUEST_URI'.freeze
|
|
|
|
REQUEST_PATH = 'REQUEST_PATH'.freeze
|
2016-04-07 13:47:04 -04:00
|
|
|
QUERY_STRING = 'QUERY_STRING'.freeze
|
2007-10-26 05:23:10 -04:00
|
|
|
|
2011-10-14 15:15:35 -04:00
|
|
|
PATH_INFO = 'PATH_INFO'.freeze
|
|
|
|
|
2011-09-24 00:01:03 -04:00
|
|
|
PUMA_TMP_BASE = "puma".freeze
|
2007-10-26 05:23:10 -04:00
|
|
|
|
2012-09-06 01:09:42 -04:00
|
|
|
# Indicate that we couldn't parse the request
|
2014-03-05 11:09:20 -05:00
|
|
|
ERROR_400_RESPONSE = "HTTP/1.1 400 Bad Request\r\n\r\n".freeze
|
2012-09-06 01:09:42 -04:00
|
|
|
|
2007-10-26 05:23:10 -04:00
|
|
|
# The standard empty 404 response for bad requests. Use Error4040Handler for custom stuff.
|
2011-09-24 00:01:03 -04:00
|
|
|
ERROR_404_RESPONSE = "HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: Puma #{PUMA_VERSION}\r\n\r\nNOT FOUND".freeze
|
2007-10-26 05:23:10 -04:00
|
|
|
|
2014-01-30 13:23:01 -05:00
|
|
|
# The standard empty 408 response for requests that timed out.
|
|
|
|
ERROR_408_RESPONSE = "HTTP/1.1 408 Request Timeout\r\nConnection: close\r\nServer: Puma #{PUMA_VERSION}\r\n\r\n".freeze
|
|
|
|
|
2011-09-24 00:01:03 -04:00
|
|
|
CONTENT_LENGTH = "CONTENT_LENGTH".freeze
|
2007-10-26 05:23:10 -04:00
|
|
|
|
2012-09-06 01:09:42 -04:00
|
|
|
# Indicate that there was an internal error, obviously.
|
2014-03-05 11:09:20 -05:00
|
|
|
ERROR_500_RESPONSE = "HTTP/1.1 500 Internal Server Error\r\n\r\n".freeze
|
2012-09-06 01:09:42 -04:00
|
|
|
|
2007-10-26 05:23:10 -04:00
|
|
|
# A common header for indicating the server is too busy. Not used yet.
|
2011-09-24 00:01:03 -04:00
|
|
|
ERROR_503_RESPONSE = "HTTP/1.1 503 Service Unavailable\r\n\r\nBUSY".freeze
|
2007-10-26 05:23:10 -04:00
|
|
|
|
|
|
|
# The basic max request size we'll try to read.
|
2011-09-24 00:01:03 -04:00
|
|
|
CHUNK_SIZE = 16 * 1024
|
2007-10-26 05:23:10 -04:00
|
|
|
|
|
|
|
# This is the maximum header that is allowed before a client is booted. The parser detects
|
|
|
|
# this, but we'd also like to do this as well.
|
2011-09-24 00:01:03 -04:00
|
|
|
MAX_HEADER = 1024 * (80 + 32)
|
2007-10-26 05:23:10 -04:00
|
|
|
|
|
|
|
# Maximum request body size before it is moved out of memory and into a tempfile for reading.
|
2011-09-24 00:01:03 -04:00
|
|
|
MAX_BODY = MAX_HEADER
|
2007-10-26 05:23:10 -04:00
|
|
|
|
2011-09-24 00:01:03 -04:00
|
|
|
REQUEST_METHOD = "REQUEST_METHOD".freeze
|
|
|
|
HEAD = "HEAD".freeze
|
2007-10-26 05:23:10 -04:00
|
|
|
# ETag is based on the apache standard of hex mtime-size-inode (inode is 0 on win32)
|
2011-09-24 00:01:03 -04:00
|
|
|
LINE_END = "\r\n".freeze
|
|
|
|
REMOTE_ADDR = "REMOTE_ADDR".freeze
|
|
|
|
HTTP_X_FORWARDED_FOR = "HTTP_X_FORWARDED_FOR".freeze
|
2011-09-22 21:47:46 -04:00
|
|
|
|
|
|
|
SERVER_NAME = "SERVER_NAME".freeze
|
|
|
|
SERVER_PORT = "SERVER_PORT".freeze
|
|
|
|
HTTP_HOST = "HTTP_HOST".freeze
|
|
|
|
PORT_80 = "80".freeze
|
2013-02-19 22:23:02 -05:00
|
|
|
PORT_443 = "443".freeze
|
2012-04-28 12:52:48 -04:00
|
|
|
LOCALHOST = "localhost".freeze
|
2015-07-02 11:29:26 -04:00
|
|
|
LOCALHOST_IP = "127.0.0.1".freeze
|
2016-01-06 13:12:09 -05:00
|
|
|
LOCALHOST_ADDR = "127.0.0.1:0".freeze
|
2011-09-22 21:47:46 -04:00
|
|
|
|
|
|
|
SERVER_PROTOCOL = "SERVER_PROTOCOL".freeze
|
|
|
|
HTTP_11 = "HTTP/1.1".freeze
|
|
|
|
|
|
|
|
SERVER_SOFTWARE = "SERVER_SOFTWARE".freeze
|
|
|
|
GATEWAY_INTERFACE = "GATEWAY_INTERFACE".freeze
|
|
|
|
CGI_VER = "CGI/1.2".freeze
|
|
|
|
|
2011-12-05 12:01:19 -05:00
|
|
|
STOP_COMMAND = "?".freeze
|
|
|
|
HALT_COMMAND = "!".freeze
|
2012-04-04 11:38:22 -04:00
|
|
|
RESTART_COMMAND = "R".freeze
|
2011-09-15 01:07:27 -04:00
|
|
|
|
2011-12-01 17:16:18 -05:00
|
|
|
RACK_INPUT = "rack.input".freeze
|
|
|
|
RACK_URL_SCHEME = "rack.url_scheme".freeze
|
|
|
|
RACK_AFTER_REPLY = "rack.after_reply".freeze
|
2012-06-04 15:00:11 -04:00
|
|
|
PUMA_SOCKET = "puma.socket".freeze
|
2013-02-06 11:43:15 -05:00
|
|
|
PUMA_CONFIG = "puma.config".freeze
|
2015-01-13 23:11:26 -05:00
|
|
|
PUMA_PEERCERT = "puma.peercert".freeze
|
2011-12-01 17:16:18 -05:00
|
|
|
|
|
|
|
HTTP = "http".freeze
|
|
|
|
HTTPS = "https".freeze
|
|
|
|
|
|
|
|
HTTPS_KEY = "HTTPS".freeze
|
|
|
|
|
|
|
|
HTTP_VERSION = "HTTP_VERSION".freeze
|
|
|
|
HTTP_CONNECTION = "HTTP_CONNECTION".freeze
|
2016-07-25 01:10:13 -04:00
|
|
|
HTTP_EXPECT = "HTTP_EXPECT".freeze
|
|
|
|
CONTINUE = "100-continue".freeze
|
2011-12-01 17:16:18 -05:00
|
|
|
|
2016-07-25 01:10:13 -04:00
|
|
|
HTTP_11_100 = "HTTP/1.1 100 Continue\r\n\r\n".freeze
|
2011-12-01 17:16:18 -05:00
|
|
|
HTTP_11_200 = "HTTP/1.1 200 OK\r\n".freeze
|
|
|
|
HTTP_10_200 = "HTTP/1.0 200 OK\r\n".freeze
|
|
|
|
|
|
|
|
CLOSE = "close".freeze
|
2016-01-06 13:11:37 -05:00
|
|
|
KEEP_ALIVE = "keep-alive".freeze
|
2011-12-01 17:16:18 -05:00
|
|
|
|
2016-01-06 13:11:37 -05:00
|
|
|
CONTENT_LENGTH2 = "content-length".freeze
|
2011-12-01 17:16:18 -05:00
|
|
|
CONTENT_LENGTH_S = "Content-Length: ".freeze
|
2016-01-06 13:11:37 -05:00
|
|
|
TRANSFER_ENCODING = "transfer-encoding".freeze
|
2016-07-25 01:02:23 -04:00
|
|
|
TRANSFER_ENCODING2 = "HTTP_TRANSFER_ENCODING".freeze
|
2011-12-01 17:16:18 -05:00
|
|
|
|
|
|
|
CONNECTION_CLOSE = "Connection: close\r\n".freeze
|
|
|
|
CONNECTION_KEEP_ALIVE = "Connection: Keep-Alive\r\n".freeze
|
|
|
|
|
|
|
|
TRANSFER_ENCODING_CHUNKED = "Transfer-Encoding: chunked\r\n".freeze
|
|
|
|
CLOSE_CHUNKED = "0\r\n\r\n".freeze
|
|
|
|
|
2016-07-25 01:02:23 -04:00
|
|
|
CHUNKED = "chunked".freeze
|
|
|
|
|
2011-12-01 17:16:18 -05:00
|
|
|
COLON = ": ".freeze
|
|
|
|
|
|
|
|
NEWLINE = "\n".freeze
|
2013-02-06 01:39:16 -05:00
|
|
|
|
|
|
|
HIJACK_P = "rack.hijack?".freeze
|
|
|
|
HIJACK = "rack.hijack".freeze
|
|
|
|
HIJACK_IO = "rack.hijack_io".freeze
|
2017-10-04 08:30:16 -04:00
|
|
|
|
|
|
|
EARLY_HINTS = "rack.early_hints".freeze
|
2019-03-20 00:06:25 -04:00
|
|
|
|
|
|
|
# Mininum interval to checks worker health
|
|
|
|
WORKER_CHECK_INTERVAL = 5
|
|
|
|
|
2007-10-26 05:23:10 -04:00
|
|
|
end
|
2011-09-15 01:07:27 -04:00
|
|
|
end
|