Sha256: 219260e92dfb74b0a69b00df7f33847cd2405d35c607bc0558c5f15ac82df99a

Contents?: true

Size: 1.71 KB

Versions: 36

Compression:

Stored size: 1.71 KB

Contents

module Billy
  module Handler
    ##
    #
    # Handles an incoming HTTP request and returns a response.
    #
    # This method accepts HTTP request parameters and must return
    # a response hash containing the keys :status, :headers,
    # and :content, or nil if the request cannot be fulfilled.
    #
    # @param  [String] http_method  The HTTP method used, e.g. 'http' or 'https'
    # @param  [String] url          The URL requested.
    # @param  [String] headers      The headers of the HTTP request.
    # @param  [String] body         The body of the HTTP request.
    # @return [Hash]                A hash with the keys [:status, :headers, :content]
    #                               Returns {:error => "Some error message"} if a failure occurs.
    #                               Returns nil if the request cannot be fulfilled.
    def handle_request(_http_method, _url, _headers, _body)
      { error: 'The handler has not overridden the handle_request method!' }
    end

    ##
    #
    # Checks if the Handler can respond to the given request.
    #
    # @param  [String] http_method  The HTTP method used, e.g. 'http' or 'https'
    # @param  [String] url          The URL requested.
    # @param  [String] headers      The headers of the HTTP request.
    # @param  [String] body         The body of the HTTP request.
    # @return [Boolean]             True if the Handler can respond to the request, else false.
    #
    def handles_request?(_http_method, _url, _headers, _body)
      false
    end

    ##
    #
    # Resets the Handler to the default/new state
    #
    # This allows the handler to be set back to its default state
    # at the end of tests or whenever else necessary.
    #
    def reset; end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
puffing-billy-4.0.0 lib/billy/handlers/handler.rb
puffing-billy-3.2.0 lib/billy/handlers/handler.rb
puffing-billy-3.1.0 lib/billy/handlers/handler.rb
puffing-billy-3.0.4 lib/billy/handlers/handler.rb
puffing-billy-3.0.3 lib/billy/handlers/handler.rb
puffing-billy-3.0.2 lib/billy/handlers/handler.rb
puffing-billy-3.0.1 lib/billy/handlers/handler.rb
puffing-billy-3.0.0 lib/billy/handlers/handler.rb
puffing-billy-2.4.1 lib/billy/handlers/handler.rb
puffing-billy-2.4.0 lib/billy/handlers/handler.rb
puffing-billy-2.3.1 lib/billy/handlers/handler.rb
puffing-billy-2.3.0 lib/billy/handlers/handler.rb
puffing-billy-2.2.0 lib/billy/handlers/handler.rb
puffing-billy-2.1.1 lib/billy/handlers/handler.rb
puffing-billy-2.1.0 lib/billy/handlers/handler.rb
puffing-billy-2.0.0 lib/billy/handlers/handler.rb
puffing-billy-1.1.3 lib/billy/handlers/handler.rb
puffing-billy-1.1.2 lib/billy/handlers/handler.rb
puffing-billy-1.1.1 lib/billy/handlers/handler.rb
puffing-billy-1.1.0 lib/billy/handlers/handler.rb