Skip to content

Commit 6d0b9ad

Browse files
authored
Adding #hijacked? method to connection (#30)
1 parent 0b32c2f commit 6d0b9ad

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/protocol/http1/connection.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ def write_connection_header(version)
104104
def write_upgrade_header(upgrade)
105105
@stream.write("connection: upgrade\r\nupgrade: #{upgrade}\r\n")
106106
end
107+
108+
# Indicates whether the connection has been hijacked meaning its
109+
# IO has been handed over and is not usable anymore.
110+
# @return [Boolean] hijack status
111+
def hijacked?
112+
@stream.nil?
113+
end
107114

108115
# Effectively close the connection and return the underlying IO.
109116
# @return [IO] the underlying non-blocking IO.

test/protocol/http1/hijack.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@
1919
server_wrapper = server.hijack!
2020
expect(server.persistent).to be == false
2121
end
22+
23+
it "should repord itself as #hijacked? after the hijack" do
24+
expect(server.hijacked?).to be == false
25+
server.hijack!
26+
expect(server.hijacked?).to be == true
27+
end
2228

2329
it "should use non-chunked output" do
2430
expect(body).to receive(:ready?).and_return(false)
2531
expect(body).to receive(:empty?).and_return(false)
26-
expect(body).to receive(:length).and_return(nil)
32+
expect(body).to receive(:length).twice.and_return(nil)
2733
expect(body).to receive(:each).and_return(nil)
2834

2935
expect(server).to receive(:write_body_and_close)

0 commit comments

Comments
 (0)