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

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

Direct Known Subclasses

Client, Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream, version) ⇒ Connection

Returns a new instance of Connection.



16
17
18
19
20
# File 'lib/async/http/protocol/http1/connection.rb', line 16

def initialize(stream, version)
	super(stream)
	
	@version = version
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



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

def count
  @count
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

#as_jsonObject



26
27
28
# File 'lib/async/http/protocol/http1/connection.rb', line 26

def as_json(...)
	to_s
end

#concurrencyObject



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

def concurrency
	1
end

#http1?Boolean

Returns:

  • (Boolean)


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

def http1?
	true
end

#http2?Boolean

Returns:

  • (Boolean)


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

def http2?
	false
end

#peerObject



54
55
56
# File 'lib/async/http/protocol/http1/connection.rb', line 54

def peer
	@stream.io
end

#read_lineObject



50
51
52
# File 'lib/async/http/protocol/http1/connection.rb', line 50

def read_line
	@stream.read_until(CRLF) or raise EOFError, "Could not read line!"
end

#read_line?Boolean

Returns:

  • (Boolean)


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

def read_line?
	@stream.read_until(CRLF)
rescue Errno::ECONNRESET
	return nil
end

#reusable?Boolean

Returns:

  • (Boolean)


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

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

#to_jsonObject



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

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

#to_sObject



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

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

#viable?Boolean

Can we use this connection to make requests?

Returns:

  • (Boolean)


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

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