Skip to content

Commit

Permalink
Add support for writing interim (informational) responses. (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Oct 24, 2023
1 parent b14df9c commit ac2b327
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/protocol/http1/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ def write_response(version, status, headers, reason = Reason::DESCRIPTIONS[statu
write_headers(headers)
end

def write_interim_response(version, status, headers, reason = Reason::DESCRIPTIONS[status])
@stream.write("#{version} #{status} #{reason}\r\n")

write_headers(headers)

@stream.write("\r\n")
@stream.flush
end

def write_headers(headers)
headers.each do |name, value|
# Convert it to a string:
Expand Down
9 changes: 9 additions & 0 deletions test/protocol/http1/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@
end
end

with '#write_interim_response' do
it 'can write iterm response' do
server.write_interim_response("HTTP/1.1", 100, {})
server.close

expect(client.stream.read).to be == "HTTP/1.1 100 Continue\r\n\r\n"
end
end

with '#persistent?' do
describe "HTTP 1.0" do
it "should not be persistent by default" do
Expand Down

0 comments on commit ac2b327

Please sign in to comment.