Module: Billy::Handler

Included in:
CacheHandler, ProxyHandler, RequestHandler, StubHandler
Defined in:
lib/billy/handlers/handler.rb

Instance Method Summary collapse

Instance Method Details

#handle_request(_http_method, _url, _headers, _body) ⇒ Hash

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.

Parameters:

  • http_method (String)

    The HTTP method used, e.g. ‘http’ or ‘https’

  • url (String)

    The URL requested.

  • headers (String)

    The headers of the HTTP request.

  • body (String)

    The body of the HTTP request.

Returns:

  • (Hash)

    A hash with the keys [:status, :headers, :content] Returns => “Some error message” if a failure occurs. Returns nil if the request cannot be fulfilled.



18
19
20
# File 'lib/billy/handlers/handler.rb', line 18

def handle_request(_http_method, _url, _headers, _body)
  { error: 'The handler has not overridden the handle_request method!' }
end

#handles_request?(_http_method, _url, _headers, _body) ⇒ Boolean

Checks if the Handler can respond to the given request.

Parameters:

  • http_method (String)

    The HTTP method used, e.g. ‘http’ or ‘https’

  • url (String)

    The URL requested.

  • headers (String)

    The headers of the HTTP request.

  • body (String)

    The body of the HTTP request.

Returns:

  • (Boolean)

    True if the Handler can respond to the request, else false.



32
33
34
# File 'lib/billy/handlers/handler.rb', line 32

def handles_request?(_http_method, _url, _headers, _body)
  false
end

#resetObject

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.



43
# File 'lib/billy/handlers/handler.rb', line 43

def reset; end