Sha256: 1c92eeb2376ddfbf53436fd8b2f2c7e1c6f1248cf3a48db7e1acde74ea09c92a

Contents?: true

Size: 1.5 KB

Versions: 13

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2018-2024, by Samuel Williams.
# Copyright, 2023, by Josh Huber.

require_relative "../response"

module Async
	module HTTP
		module Protocol
			module HTTP1
				class Response < Protocol::Response
					def self.read(connection, request)
						while parts = connection.read_response(request.method)
							response = self.new(connection, *parts)
							
							if response.final?
								return response
							else
								request.send_interim_response(response.status, response.headers)
							end
						end
					end
					
					UPGRADE = "upgrade"
					
					# @attribute [String] The HTTP response line reason.
					attr :reason
					
					# @parameter reason [String] HTTP response line reason phrase.
					def initialize(connection, version, status, reason, headers, body)
						@connection = connection
						@reason = reason
						
						# Technically, there should never be more than one value for the upgrade header, but we'll just take the first one to avoid complexity.
						protocol = headers.delete(UPGRADE)&.first
						
						super(version, status, headers, body, protocol)
					end
					
					def pool=(pool)
						if @connection.idle? or @connection.closed?
							pool.release(@connection)
						else
							@connection.pool = pool
						end
					end
					
					def connection
						@connection
					end
					
					def hijack?
						@body.nil?
					end
					
					def hijack!
						@connection.hijack!
					end
				end
			end
		end
	end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
async-http-0.84.0 lib/async/http/protocol/http1/response.rb
async-http-0.83.1 lib/async/http/protocol/http1/response.rb
async-http-0.83.0 lib/async/http/protocol/http1/response.rb
async-http-0.82.3 lib/async/http/protocol/http1/response.rb
async-http-0.82.2 lib/async/http/protocol/http1/response.rb
async-http-0.82.1 lib/async/http/protocol/http1/response.rb
async-http-0.82.0 lib/async/http/protocol/http1/response.rb
async-http-0.81.0 lib/async/http/protocol/http1/response.rb
async-http-0.80.1 lib/async/http/protocol/http1/response.rb
async-http-0.80.0 lib/async/http/protocol/http1/response.rb
async-http-0.79.0 lib/async/http/protocol/http1/response.rb
async-http-0.78.0 lib/async/http/protocol/http1/response.rb
async-http-0.77.0 lib/async/http/protocol/http1/response.rb