Skip to content

Adding #hijacked? method to connection #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading