Class: Vigiles::Archive::Request

Inherits:
T::Struct
  • Object
show all
Defined in:
lib/vigiles/archive/request.rb

Defined Under Namespace

Classes: InvalidParameterError

Class Method Summary collapse

Class Method Details

.from(request) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/vigiles/archive/request.rb', line 47

def self.from(request)
  preferred_headers = Vigiles.spec.request_headers
  available_headers = request.original_headers
  recorded_headers  = (available_headers if preferred_headers.empty?)
  recorded_headers ||= preferred_headers.to_h { [_1, available_headers[_1]] }
  unfucked_headers = recorded_headers.transform_keys { best_effort_unfuck_http_header _1 }

  Request.new(
    content_type: request.content_type || (raise InvalidParameterError, "content_type"),
    user_agent: request.user_agent || "unknown_user_agent",
    timestamp: DateTime.now,
    remote_ip: IPAddr.new(request.remote_ip),
    protocol: request.protocol,
    headers: unfucked_headers,
    origin: request.origin || "unknown_origin_url",
    payload: Utilities::JSON.parse_benignly(request.body.read),
    http_method: Types::HttpMethod.deserialize(request.method),
    path: request.path,
    url: Utilities::URI.parse_into_http_or_https(request.url),
    id: request.request_id
  )
end