Sha256: d3231e8ac8fdb203d063fc9ecbc6b1bf514261ddf615f0004275a3a4dbcbb179

Contents?: true

Size: 1.26 KB

Versions: 16

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

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

require 'protocol/http1'

require_relative 'request'
require_relative 'response'

module Async
	module HTTP
		module Protocol
			module HTTP1
				class Connection < ::Protocol::HTTP1::Connection
					def initialize(stream, version)
						super(stream)
						
						@ready = true
						@version = version
					end
					
					def to_s
						"\#<#{self.class} negotiated #{@version}, currently #{@ready ? 'ready' : 'in-use'}>"
					end
					
					def as_json(...)
						to_s
					end
					
					def to_json(...)
						as_json.to_json(...)
					end
					
					attr :version
					
					def http1?
						true
					end
					
					def http2?
						false
					end
					
					def read_line?
						@stream.read_until(CRLF)
					end
					
					def read_line
						@stream.read_until(CRLF) or raise EOFError, "Could not read line!"
					end
					
					def peer
						@stream.io
					end
					
					attr :count
					
					def concurrency
						1
					end
					
					# Can we use this connection to make requests?
					def viable?
						@ready && @stream&.readable?
					end
					
					def reusable?
						@ready && @persistent && @stream && !@stream.closed?
					end
				end
			end
		end
	end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
async-http-0.76.0 lib/async/http/protocol/http1/connection.rb
async-http-0.75.0 lib/async/http/protocol/http1/connection.rb
async-http-0.74.0 lib/async/http/protocol/http1/connection.rb
async-http-0.73.0 lib/async/http/protocol/http1/connection.rb
async-http-0.72.0 lib/async/http/protocol/http1/connection.rb
async-http-0.71.0 lib/async/http/protocol/http1/connection.rb
async-http-0.70.0 lib/async/http/protocol/http1/connection.rb
async-http-0.69.0 lib/async/http/protocol/http1/connection.rb
async-http-0.68.0 lib/async/http/protocol/http1/connection.rb
async-http-0.67.1 lib/async/http/protocol/http1/connection.rb
async-http-0.67.0 lib/async/http/protocol/http1/connection.rb
async-http-0.66.2 lib/async/http/protocol/http1/connection.rb
async-http-0.66.1 lib/async/http/protocol/http1/connection.rb
async-http-0.66.0 lib/async/http/protocol/http1/connection.rb
async-http-0.65.1 lib/async/http/protocol/http1/connection.rb
async-http-0.65.0 lib/async/http/protocol/http1/connection.rb