Skip to content

Commit 206e138

Browse files
committed
Move count to Async::HTTP::Server.
1 parent 5bded8a commit 206e138

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

lib/async/http/protocol/http2/client.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ def create_response
3232
def call(request)
3333
raise ::Protocol::HTTP2::Error, "Connection closed!" if self.closed?
3434

35-
@count += 1
36-
3735
response = create_response
3836
write_request(response, request)
3937
read_response(response)

lib/async/http/protocol/http2/connection.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ module Connection
2929
def initialize(*)
3030
super
3131

32-
@count = 0
3332
@reader = nil
3433

3534
# Writing multiple frames at the same time can cause odd problems if frames are only partially written. So we use a semaphore to ensure frames are written in their entirety.
@@ -41,7 +40,7 @@ def synchronize(&block)
4140
end
4241

4342
def to_s
44-
"\#<#{self.class} #{@count} requests, #{@streams.count} active streams>"
43+
"\#<#{self.class} #{@streams.count} active streams>"
4544
end
4645

4746
def as_json(...)

lib/async/http/protocol/http2/server.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ def each(task: Task.current)
5151
@requests&.async do |task, request|
5252
task.annotate("Incoming request: #{request.method} #{request.path.inspect}.")
5353

54-
@count += 1
55-
5654
task.defer_stop do
5755
response = yield(request)
5856
rescue

lib/async/http/server.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def initialize(app, endpoint, protocol: endpoint.protocol, scheme: endpoint.sche
2424
@endpoint = endpoint
2525
@protocol = protocol
2626
@scheme = scheme
27+
28+
@count = 0
2729
end
2830

2931
def as_json(...)
@@ -42,6 +44,14 @@ def to_json(...)
4244
attr :protocol
4345
attr :scheme
4446

47+
attr :count
48+
49+
def call(...)
50+
@count += 1
51+
52+
super
53+
end
54+
4555
def accept(peer, address, task: Task.current)
4656
connection = @protocol.server(peer)
4757

test/async/http/protocol/http2.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
response = client.get("/")
1818
connection = response.connection
1919

20-
expect(connection.as_json).to be =~ /#<Async::HTTP::Protocol::HTTP2::Client 1 requests, \d+ active streams>/
20+
expect(connection.as_json).to be =~ /#<Async::HTTP::Protocol::HTTP2::Client \d+ active streams>/
2121
ensure
2222
response&.close
2323
end

0 commit comments

Comments
 (0)