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
21
# File 'lib/async/http/protocol/http1/connection.rb', line 16

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

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



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

def count
  @count
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

#as_jsonObject



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

def as_json(...)
	to_s
end

#concurrencyObject



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

def concurrency
	1
end

#http1?Boolean

Returns:

  • (Boolean)


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

def http1?
	true
end

#http2?Boolean

Returns:

  • (Boolean)


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

def http2?
	false
end

#peerObject



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

def peer
	@stream.io
end

#read_lineObject



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

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

#read_line?Boolean

Returns:

  • (Boolean)


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

def read_line?
	@stream.read_until(CRLF)
end

#reusable?Boolean

Returns:

  • (Boolean)


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

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

#to_jsonObject



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

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

#to_sObject



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

def to_s
	"\#<#{self.class} negotiated #{@version}, currently #{@ready ? 'ready' : 'in-use'}>"
end

#viable?Boolean

Can we use this connection to make requests?

Returns:

  • (Boolean)


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

def viable?
	@ready && @stream&.readable?
end