diff --git a/lib/protocol/http1/connection.rb b/lib/protocol/http1/connection.rb index 7cfb0ba..49e4cf1 100644 --- a/lib/protocol/http1/connection.rb +++ b/lib/protocol/http1/connection.rb @@ -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. diff --git a/test/protocol/http1/hijack.rb b/test/protocol/http1/hijack.rb index cb29384..e91595f 100644 --- a/test/protocol/http1/hijack.rb +++ b/test/protocol/http1/hijack.rb @@ -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)