class Gem::GemcutterUtilities::WebauthnListener::Response - Documentation for Ruby 4.0
Description: Documentation for the Gem::GemcutterUtilities::WebauthnListener::Response class
Keywords: ruby,class,Gem::GemcutterUtilities::WebauthnListener::Response

🔍

No recent searches

# class Gem::GemcutterUtilities::WebauthnListener::Response

### Attributes

http_response [R]

### Public Class Methods

for (host)
Source

    # File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 31
    def self.for(host)
      new(host)
    end

new (host)
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 ()
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 ()
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 ()
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 ()
Source

    # File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 72
    def add_connection_header
      @http_response["connection"] = "close"
    end

body ()
Source

    # File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 60
    def body; end

build_http_response ()
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

code ()
Source

    # File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 52
    def code
      raise NotImplementedError
    end

Must be implemented in subclasses

reason_phrase ()
Source

    # File lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb, line 56
    def reason_phrase
      raise NotImplementedError
    end