Skip to content

Commit

Permalink
Adding #hijacked? method to connection (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
yard authored Apr 5, 2024
1 parent 0b32c2f commit 6d0b9ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/protocol/http1/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ def write_connection_header(version)
def write_upgrade_header(upgrade)
@stream.write("connection: upgrade\r\nupgrade: #{upgrade}\r\n")
end

# Indicates whether the connection has been hijacked meaning its
# IO has been handed over and is not usable anymore.
# @return [Boolean] hijack status
def hijacked?
@stream.nil?
end

# Effectively close the connection and return the underlying IO.
# @return [IO] the underlying non-blocking IO.
Expand Down
8 changes: 7 additions & 1 deletion test/protocol/http1/hijack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@
server_wrapper = server.hijack!
expect(server.persistent).to be == false
end

it "should repord itself as #hijacked? after the hijack" do
expect(server.hijacked?).to be == false
server.hijack!
expect(server.hijacked?).to be == true
end

it "should use non-chunked output" do
expect(body).to receive(:ready?).and_return(false)
expect(body).to receive(:empty?).and_return(false)
expect(body).to receive(:length).and_return(nil)
expect(body).to receive(:length).twice.and_return(nil)
expect(body).to receive(:each).and_return(nil)

expect(server).to receive(:write_body_and_close)
Expand Down

0 comments on commit 6d0b9ad

Please sign in to comment.