class Gem::GemcutterUtilities::WebauthnListener::Response

Attributes

http_response[R]

Public Class Methods

for(host) click to toggle source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 31
def self.for(host)
  new(host)
end
new(host) click to toggle source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 35
def initialize(host)
  @host = host

  build_http_response
end

Public Instance Methods

to_s() click to toggle source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 41
def to_s
  status_line = "HTTP/#{@http_response.http_version} #{@http_response.code} #{@http_response.message}\r\n"
  headers = @http_response.to_hash.map {|header, value| "#{header}: #{value.join(", ")}\r\n" }.join + "\r\n"
  body = @http_response.body ? "#{@http_response.body}\n" : ""

  status_line + headers + body
end

Private Instance Methods

add_access_control_headers() click to toggle source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 76
def add_access_control_headers
  @http_response["access-control-allow-origin"] = @host
  @http_response["access-control-allow-methods"] = "POST"
  @http_response["access-control-allow-headers"] = %w[Content-Type Authorization x-csrf-token]
end
add_body() click to toggle source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 82
def add_body
  return unless body
  @http_response["content-type"] = "text/plain; charset=utf-8"
  @http_response["content-length"] = body.bytesize
  @http_response.instance_variable_set(:@body, body)
end
add_connection_header() click to toggle source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 72
def add_connection_header
  @http_response["connection"] = "close"
end
body() click to toggle source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 60
def body; end
build_http_response() click to toggle source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 62
def build_http_response
  response_class = Net::HTTPResponse::CODE_TO_OBJ[code.to_s]
  @http_response = response_class.new("1.1", code, reason_phrase)
  @http_response.instance_variable_set(:@read, true)

  add_connection_header
  add_access_control_headers
  add_body
end
code() click to toggle source

Must be implemented in subclasses

# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 52
def code
  raise NotImplementedError
end
reason_phrase() click to toggle source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 56
def reason_phrase
  raise NotImplementedError
end