Class: Async::HTTP::Protocol::HTTP1::Connection

Inherits:
Protocol::HTTP1::Connection
  • Object
show all
Defined in:
lib/async/http/protocol/http1/connection.rb

Overview

An HTTP/1 connection that wraps an IO stream with version and state tracking.

Direct Known Subclasses

Client, Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream, version, **options) ⇒ Connection

Initialize the connection with an IO stream and HTTP version.



22
23
24
25
26
27
# File 'lib/async/http/protocol/http1/connection.rb', line 22

def initialize(stream, version, **options)
	super(stream, **options)
	
	# On the client side, we need to send the HTTP version with the initial request. On the server side, there are some scenarios (bad request) where we don't know the request version. In those cases, we use this value, which is either hard coded based on the protocol being used, OR could be negotiated during the connection setup (e.g. ALPN).
	@version = version
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



61
62
63
# File 'lib/async/http/protocol/http1/connection.rb', line 61

def count
  @count
end

#versionObject (readonly)

Returns the value of attribute version.



44
45
46
# File 'lib/async/http/protocol/http1/connection.rb', line 44

def version
  @version
end

Instance Method Details

#as_jsonObject



35
36
37
# File 'lib/async/http/protocol/http1/connection.rb', line 35

def as_json(...)
	to_s
end

#concurrencyObject



64
65
66
# File 'lib/async/http/protocol/http1/connection.rb', line 64

def concurrency
	1
end

#http1?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/async/http/protocol/http1/connection.rb', line 47

def http1?
	true
end

#http2?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/async/http/protocol/http1/connection.rb', line 52

def http2?
	false
end

#peerObject



57
58
59
# File 'lib/async/http/protocol/http1/connection.rb', line 57

def peer
	@peer ||= ::Protocol::HTTP::Peer.for(@stream.io)
end

#reusable?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/async/http/protocol/http1/connection.rb', line 74

def reusable?
	@persistent && @stream && !@stream.closed?
end

#to_jsonObject



40
41
42
# File 'lib/async/http/protocol/http1/connection.rb', line 40

def to_json(...)
	as_json.to_json(...)
end

#to_sObject



30
31
32
# File 'lib/async/http/protocol/http1/connection.rb', line 30

def to_s
	"\#<#{self.class} negotiated #{@version}, #{@state}>"
end

#viable?Boolean

Can we use this connection to make requests?

Returns:

  • (Boolean)


69
70
71
# File 'lib/async/http/protocol/http1/connection.rb', line 69

def viable?
	self.idle? && @stream&.readable?
end