Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 18, 2024
1 parent 6aa2b65 commit dbbf147
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/protocol/http1/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def write_request(authority, method, path, version, headers)
end

def write_response(version, status, headers, reason = Reason::DESCRIPTIONS[status])
raise ProtocolError, "Cannot write response in #{@state}!" unless @state == :open
raise ProtocolError, "Cannot write response in #{@state}!" unless @state == :open or @state == :half_closed_remote

# Safari WebSockets break if no reason is given:
@stream.write("#{version} #{status} #{reason}\r\n")
Expand Down Expand Up @@ -288,6 +288,10 @@ def read_request

body = read_request_body(method, headers)

if body.nil?
self.receive_end_stream!
end

@count += 1

return headers.delete(HOST), method, path, version, headers, body
Expand Down Expand Up @@ -489,7 +493,7 @@ def idle!
def closed!
raise ProtocolError, "Cannot close in #{@state}!" unless @state == :half_closed_local or @state == :half_closed_remote

if self.persistent?
if @persistent
self.idle!
else
@state = :closed
Expand Down
6 changes: 4 additions & 2 deletions test/protocol/http1/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,12 @@

request = server.read_request
expect(request).to be == ["localhost", "GET", "/", "HTTP/1.1", {}, nil]
expect(server).to be(:open?)
expect(server).to be(:half_closed_remote?)

server.write_response("HTTP/1.1", 200, {}, [])
expect(server).to be(:idle?)
server.write_body("HTTP/1.1", nil)

expect(server).to be(:idle?)
end
end
end

0 comments on commit dbbf147

Please sign in to comment.