Sha256: 86304c63f4195a8c2c100d218a41082b10134b553018b368a9bccfb5444e8091

Contents?: true

Size: 1.51 KB

Versions: 22

Compression:

Stored size: 1.51 KB

Contents

require 'puma/const'
require 'stringio'

module Puma
  # The default implement of an event sink object used by Server
  # for when certain kinds of events occur in the life of the server.
  #
  # The methods available are the events that the Server fires.
  #
  class Events

    include Const

    # Create an Events object that prints to +stdout+ and +stderr+.
    #
    def initialize(stdout, stderr)
      @stdout = stdout
      @stderr = stderr
    end

    attr_reader :stdout, :stderr

    # An HTTP parse error has occured.
    # +server+ is the Server object, +env+ the request, and +error+ a
    # parsing exception.
    #
    def parse_error(server, env, error)
      @stderr.puts "#{Time.now}: HTTP parse error, malformed request (#{env[HTTP_X_FORWARDED_FOR] || env[REMOTE_ADDR]}): #{error.inspect}"
      @stderr.puts "#{Time.now}: ENV: #{env.inspect}\n---\n"
    end

    # An unknown error has occured.
    # +server+ is the Server object, +env+ the request, +error+ an exception
    # object, and +kind+ some additional info.
    #
    def unknown_error(server, error, kind="Unknown")
      if error.respond_to? :render
        error.render "#{Time.now}: #{kind} error", @stderr
      else
        @stderr.puts "#{Time.now}: #{kind} error: #{error.inspect}"
        @stderr.puts error.backtrace.join("\n")
      end
    end

    DEFAULT = new(STDOUT, STDERR)

    # Returns an Events object which writes it's status to 2 StringIO
    # objects.
    #
    def self.strings
      Events.new StringIO.new, StringIO.new
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
puma-1.4.0-java lib/puma/events.rb
puma-1.4.0 lib/puma/events.rb
puma-1.3.1-java lib/puma/events.rb
puma-1.3.1 lib/puma/events.rb
puma-1.3.0-java lib/puma/events.rb
puma-1.3.0 lib/puma/events.rb
puma-1.2.2-java lib/puma/events.rb
puma-1.2.2 lib/puma/events.rb
puma-1.2.1-java lib/puma/events.rb
puma-1.2.1 lib/puma/events.rb
puma-1.2.0-java lib/puma/events.rb
puma-1.2.0 lib/puma/events.rb
puma-1.1.1-java lib/puma/events.rb
puma-1.1.1 lib/puma/events.rb
puma-1.1.0-java lib/puma/events.rb
puma-1.1.0 lib/puma/events.rb
puma-1.0.0-java lib/puma/events.rb
puma-1.0.0 lib/puma/events.rb
puma-0.9.5-java lib/puma/events.rb
puma-0.9.5 lib/puma/events.rb