Class: Gem::GemcutterUtilities::WebauthnListener::Response
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb |
Class Method Summary
- .for(host)
- .new(host) ⇒ Response constructor
Instance Attribute Summary
- #http_response readonly
Instance Method Summary
- #to_s
- #add_access_control_headers private
- #add_body private
- #add_connection_header private
- #body private
- #build_http_response private
-
#code
private
Must be implemented in subclasses.
- #reason_phrase private
Constructor Details
.new(host) ⇒ Response
# File 'lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb', line 35
def initialize(host) @host = host build_http_response end
Class Method Details
.for(host)
[ GitHub ]Instance Attribute Details
#http_response (readonly)
[ GitHub ]# File 'lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb', line 29
attr_reader :http_response
Instance Method Details
#add_access_control_headers (private)
[ GitHub ]# 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 (private)
[ GitHub ]#add_connection_header (private)
[ GitHub ]# File 'lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb', line 72
def add_connection_header @http_response["connection"] = "close" end
#body (private)
[ GitHub ]# File 'lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb', line 60
def body; end
#build_http_response (private)
[ GitHub ]# 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 (private)
Must be implemented in subclasses
# File 'lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb', line 52
def code raise NotImplementedError end
#reason_phrase (private)
# File 'lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb', line 56
def reason_phrase raise NotImplementedError end
#to_s
[ GitHub ]# 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.}\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