Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 12, 2023
1 parent 619d3b3 commit 7d2dea1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
22 changes: 20 additions & 2 deletions fixtures/async/http/a_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,26 @@ module HTTP
end
end

with "huge body", timeout: 600 do
let(:body) {::Protocol::HTTP::Body::File.open("/dev/zero", size: 512*1024**2)}
with "interim response" do
let(:app) do
::Protocol::HTTP::Middleware.for do |request|
request.write_interim_response(
::Protocol::HTTP::Response[103, [["link", "</style.css>; rel=preload; as=style"]]]
)

::Protocol::HTTP::Response[200, {}, ["Hello World"]]
end
end

it "can read informational response" do
response = client.get("/")
expect(response).to be(:success?)
expect(response.read).to be == "Hello World"
end
end

with "huge body" do
let(:body) {::Protocol::HTTP::Body::File.open("/dev/zero", size: 8*1024**2)}

let(:app) do
::Protocol::HTTP::Middleware.for do |request|
Expand Down
2 changes: 1 addition & 1 deletion gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# gem "traces", path: "../traces"

# gem "protocol-http", path: "../protocol-http"
# gem "protocol-http1", path: "../protocol-http1"
gem "protocol-http1", path: "../protocol-http1"
# gem "protocol-http2", path: "../protocol-http2"
# gem "protocol-hpack", path: "../protocol-hpack"

Expand Down
4 changes: 4 additions & 0 deletions lib/async/http/protocol/http1/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def hijack?
def hijack!
@connection.hijack!
end

def write_interim_response(response)
@connection.write_interim_response(response.version, response.status, response.headers)
end
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions lib/async/http/protocol/http2/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ def send_response(response)
@stream.send_headers(nil, headers, ::Protocol::HTTP2::END_STREAM)
end
end

def write_interim_response(response)
protocol_headers = [
[STATUS, response.status]
]

headers = ::Protocol::HTTP::Headers::Merged.new(protocol_headers, response.headers)

@stream.send_headers(nil, headers)
end
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/async/http/protocol/http2/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ def accept_push_promise_stream(promised_stream_id, headers)
# This should be invoked from the background reader, and notifies the task waiting for the headers that we are done.
def receive_initial_headers(headers, end_stream)
headers.each do |key, value|
# It's guaranteed that this should be the first header:
if key == STATUS
status = Integer(value)

# Ignore informational headers:
return if status >= 100 && status < 200

@response.status = Integer(value)
elsif key == PROTOCOL
@response.protocol = value
Expand Down
3 changes: 3 additions & 0 deletions lib/async/http/protocol/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def hijack?
false
end

def write_interim_response(response)
end

def peer
if connection = self.connection
connection.peer
Expand Down

0 comments on commit 7d2dea1

Please sign in to comment.