class Gem::GemcutterUtilities::WebauthnListener::Response
Attributes
Public Class Methods
Source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 31 def self.for(host) new(host) end
Source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 35 def initialize(host) @host = host build_http_response end
Public Instance Methods
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
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
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
Source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 72 def add_connection_header @http_response["connection"] = "close" end
Source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 60 def body; end
Source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 62 def build_http_response response_class = Gem::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
Source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 52 def code raise NotImplementedError end
Must be implemented in subclasses
Source
# File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 56 def reason_phrase raise NotImplementedError end