Class: Puma::Events
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
Const
|
|
Inherits: | Object |
Defined in: | lib/puma/events.rb |
Overview
Constant Summary
-
DEFAULT =
# File 'lib/puma/events.rb', line 138new(STDOUT, STDERR)
Const
- Included
CGI_VER, CHUNKED, CHUNK_SIZE, CLOSE, CLOSE_CHUNKED, CODE_NAME, COLON, CONNECTION_CLOSE, CONNECTION_KEEP_ALIVE, CONTENT_LENGTH, CONTENT_LENGTH2, CONTENT_LENGTH_S, CONTINUE, EARLY_HINTS, ERROR_RESPONSE, FAST_TRACK_KA_TIMEOUT, FIRST_DATA_TIMEOUT, GATEWAY_INTERFACE, HALT_COMMAND, HEAD, HIJACK, HIJACK_IO, HIJACK_P, HTTP, HTTPS, HTTPS_KEY, HTTP_10_200, HTTP_11, HTTP_11_100, HTTP_11_200, HTTP_CONNECTION, HTTP_EXPECT, HTTP_HOST, HTTP_INJECTION_REGEX, HTTP_VERSION, HTTP_X_FORWARDED_FOR, HTTP_X_FORWARDED_PROTO, HTTP_X_FORWARDED_SCHEME, HTTP_X_FORWARDED_SSL, KEEP_ALIVE, LINE_END, LOCALHOST, LOCALHOST_ADDR, LOCALHOST_IP, MAX_BODY, MAX_FAST_INLINE, MAX_HEADER, NEWLINE, PATH_INFO, PERSISTENT_TIMEOUT, PORT_443, PORT_80, PUMA_CONFIG, PUMA_PEERCERT, PUMA_SERVER_STRING, PUMA_SOCKET, PUMA_TMP_BASE, PUMA_VERSION, QUERY_STRING, RACK_AFTER_REPLY, RACK_INPUT, RACK_URL_SCHEME, REMOTE_ADDR, REQUEST_METHOD, REQUEST_PATH, REQUEST_URI, RESTART_COMMAND, SERVER_NAME, SERVER_PORT, SERVER_PROTOCOL, SERVER_SOFTWARE, STOP_COMMAND, TRANSFER_ENCODING, TRANSFER_ENCODING2, TRANSFER_ENCODING_CHUNKED, WORKER_CHECK_INTERVAL, WRITE_TIMEOUT
Class Method Summary
- .new(stdout, stderr) ⇒ Events constructor
- .null
- .stdio
-
.strings
Returns an
Events
object which writes its status to 2 StringIO objects.
Instance Attribute Summary
- #formatter rw
- #stderr readonly
- #stdout readonly
Instance Method Summary
- #debug(str)
-
#error(str)
Write
str
to @stderr. -
#fire(hook, *args)
Fire callbacks for the named hook.
- #fire_on_booted!
- #format(str)
-
#log(str)
Write
str
to @stdout. - #on_booted(&block)
-
#parse_error(server, env, error)
An HTTP parse error has occurred.
-
#register(hook, obj = nil, &blk)
Register a callback for a given hook.
-
#ssl_error(server, peeraddr, peercert, error)
An SSL error has occurred.
-
#unknown_error(server, error, kind = "Unknown", env = nil)
An unknown error has occurred.
- #write(str)
Constructor Details
.new(stdout, stderr) ⇒ Events
[ GitHub ]
# File 'lib/puma/events.rb', line 30
def initialize(stdout, stderr) @formatter = DefaultFormatter.new @stdout = stdout @stderr = stderr @stdout.sync = true @stderr.sync = true @debug = ENV.key? 'PUMA_DEBUG' @hooks = Hash.new { |h,k| h[k] = [] } end
Class Method Details
.null
[ GitHub ].stdio
[ GitHub ]# File 'lib/puma/events.rb', line 147
def self.stdio Events.new $stdout, $stderr end
.strings
Returns an Events
object which writes its status to 2 StringIO objects.
Instance Attribute Details
#formatter (rw)
[ GitHub ]# File 'lib/puma/events.rb', line 44
attr_accessor :formatter
#stderr (readonly)
[ GitHub ]# File 'lib/puma/events.rb', line 43
attr_reader :stdout, :stderr
#stdout (readonly)
[ GitHub ]# File 'lib/puma/events.rb', line 43
attr_reader :stdout, :stderr
Instance Method Details
#debug(str)
[ GitHub ]# File 'lib/puma/events.rb', line 76
def debug(str) log("% #{str}") if @debug end
#error(str)
Write str
to @stderr
# File 'lib/puma/events.rb', line 82
def error(str) @stderr.puts format("ERROR: #{str}") exit 1 end
#fire(hook, *args)
Fire callbacks for the named hook
# File 'lib/puma/events.rb', line 48
def fire(hook, *args) @hooks[hook].each { |t| t.call(*args) } end
#fire_on_booted!
[ GitHub ]#format(str)
[ GitHub ]# File 'lib/puma/events.rb', line 87
def format(str) formatter.call(str) end
#log(str)
Write str
to @stdout
# File 'lib/puma/events.rb', line 68
def log(str) @stdout.puts format(str) end
#on_booted(&block)
[ GitHub ]# File 'lib/puma/events.rb', line 130
def on_booted(&block) register(:on_booted, &block) end
#parse_error(server, env, error)
# File 'lib/puma/events.rb', line 95
def parse_error(server, env, error) @stderr.puts "#{Time.now}: HTTP parse error, malformed request " \ "(#{env[HTTP_X_FORWARDED_FOR] || env[REMOTE_ADDR]}#{env[REQUEST_PATH]}): " \ "#{error.inspect}" \ "\n---\n" end
#register(hook, obj = nil, &blk)
Register a callback for a given hook
# File 'lib/puma/events.rb', line 54
def register(hook, obj=nil, &blk) if obj and blk raise "Specify either an object or a block, not both" end h = obj || blk @hooks[hook] << h h end
#ssl_error(server, peeraddr, peercert, error)
#unknown_error(server, error, kind = "Unknown", env = nil)
# File 'lib/puma/events.rb', line 115
def unknown_error(server, error, kind="Unknown", env=nil) if error.respond_to? :render error.render "#{Time.now}: #{kind} error", @stderr else if env string_block = [ "#{Time.now}: #{kind} error handling request { #{env['REQUEST_METHOD']} #{env['PATH_INFO']} }" ] string_block << error.inspect else string_block = [ "#{Time.now}: #{kind} error: #{error.inspect}" ] end string_block << error.backtrace @stderr.puts string_block.join("\n") end end
#write(str)
[ GitHub ]# File 'lib/puma/events.rb', line 72
def write(str) @stdout.write format(str) end