Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Aug 30, 2024
1 parent a423d5e commit 6f3a12f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
10 changes: 8 additions & 2 deletions guides/design-overview/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,15 @@ The value of this uni-directional flow is that it is natural for the stream to b
Interim responses are responses that are sent before the final response. They are used for things like `103 Early Hints` and `100 Continue`. These responses are sent before the final response, and are used to signal to the client that the server is still processing the request.

```ruby
body = Body::Writable.new

interim_response_callback = proc do |status, headers|
puts "Interim Response: #{status}: #{headers}"
if status == 100
# Continue sending the request body.
body.write("Hello World")
body.close
end
end

response = client.call(request, interim_response: interim_response_callback)
response = client.post("/upload", {'expect' => '100-continue'}, body, interim_response: interim_response_callback)
```
35 changes: 35 additions & 0 deletions test/protocol/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,39 @@
request.call(connection)
end
end

with "interim response" do
let(:request) {subject.new("http", "localhost", "GET", "/index.html", "HTTP/1.0", headers, body)}

it "should call block" do
request.on_interim_response do |status, headers|
expect(status).to be == 100
expect(headers).to be == {}
end

request.send_interim_response(100, {})
end

it "calls multiple blocks" do
sequence = []

request.on_interim_response do |status, headers|
sequence << 1

expect(status).to be == 100
expect(headers).to be == {}
end

request.on_interim_response do |status, headers|
sequence << 2

expect(status).to be == 100
expect(headers).to be == {}
end

request.send_interim_response(100, {})

expect(sequence).to be == [2, 1]
end
end
end

0 comments on commit 6f3a12f

Please sign in to comment.