Class: DevSuite::RequestLogger::Extractor::NetHttp

Inherits:
Base show all
Defined in:
lib/dev_suite/request_logger/extractor/net_http.rb

Constant Summary collapse

COMPONENT_KEY =
::Net::HTTP

Instance Method Summary collapse

Methods inherited from Utils::Construct::Component::Base

component_key

Instance Method Details

#extract_request(http, request) ⇒ Object

Extracts the request details from a Net::HTTP request object

Parameters:

  • http (Net::HTTP)

    The Net::HTTP object that is making the request

  • request (Net::HTTP::Request)

    The request object that is being made



12
13
14
15
16
17
18
19
20
# File 'lib/dev_suite/request_logger/extractor/net_http.rb', line 12

def extract_request(http, request)
  Request.new(
    method: request.method,
    url: build_url(http, request),
    headers: request.each_header.to_h,
    cookies: build_cookies(request),
    body: request.body,
  )
end

#extract_response(_http, response) ⇒ Response

Extracts the response details from a Net::HTTP response object

Parameters:

  • http (Net::HTTP)

    The Net::HTTP object that received the response

  • response (Net::HTTPResponse)

    The response object received

Returns:

  • (Response)

    The extracted response details



26
27
28
29
30
31
32
33
34
# File 'lib/dev_suite/request_logger/extractor/net_http.rb', line 26

def extract_response(_http, response)
  Response.new(
    status: response.code.to_i,
    message: response.message,
    headers: response.each_header.to_h,
    body: response.body,
    response_time: calculate_response_time(response),
  )
end