Skip to content

Commit 7d2dea1

Browse files
committed
WIP
1 parent 619d3b3 commit 7d2dea1

File tree

6 files changed

+44
-3
lines changed

6 files changed

+44
-3
lines changed

fixtures/async/http/a_protocol.rb

+20-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,26 @@ module HTTP
4141
end
4242
end
4343

44-
with "huge body", timeout: 600 do
45-
let(:body) {::Protocol::HTTP::Body::File.open("/dev/zero", size: 512*1024**2)}
44+
with "interim response" do
45+
let(:app) do
46+
::Protocol::HTTP::Middleware.for do |request|
47+
request.write_interim_response(
48+
::Protocol::HTTP::Response[103, [["link", "</style.css>; rel=preload; as=style"]]]
49+
)
50+
51+
::Protocol::HTTP::Response[200, {}, ["Hello World"]]
52+
end
53+
end
54+
55+
it "can read informational response" do
56+
response = client.get("/")
57+
expect(response).to be(:success?)
58+
expect(response.read).to be == "Hello World"
59+
end
60+
end
61+
62+
with "huge body" do
63+
let(:body) {::Protocol::HTTP::Body::File.open("/dev/zero", size: 8*1024**2)}
4664

4765
let(:app) do
4866
::Protocol::HTTP::Middleware.for do |request|

gems.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# gem "traces", path: "../traces"
1313

1414
# gem "protocol-http", path: "../protocol-http"
15-
# gem "protocol-http1", path: "../protocol-http1"
15+
gem "protocol-http1", path: "../protocol-http1"
1616
# gem "protocol-http2", path: "../protocol-http2"
1717
# gem "protocol-hpack", path: "../protocol-hpack"
1818

lib/async/http/protocol/http1/request.rb

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def hijack?
3838
def hijack!
3939
@connection.hijack!
4040
end
41+
42+
def write_interim_response(response)
43+
@connection.write_interim_response(response.version, response.status, response.headers)
44+
end
4145
end
4246
end
4347
end

lib/async/http/protocol/http2/request.rb

+10
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ def send_response(response)
141141
@stream.send_headers(nil, headers, ::Protocol::HTTP2::END_STREAM)
142142
end
143143
end
144+
145+
def write_interim_response(response)
146+
protocol_headers = [
147+
[STATUS, response.status]
148+
]
149+
150+
headers = ::Protocol::HTTP::Headers::Merged.new(protocol_headers, response.headers)
151+
152+
@stream.send_headers(nil, headers)
153+
end
144154
end
145155
end
146156
end

lib/async/http/protocol/http2/response.rb

+6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ def accept_push_promise_stream(promised_stream_id, headers)
3939
# This should be invoked from the background reader, and notifies the task waiting for the headers that we are done.
4040
def receive_initial_headers(headers, end_stream)
4141
headers.each do |key, value|
42+
# It's guaranteed that this should be the first header:
4243
if key == STATUS
44+
status = Integer(value)
45+
46+
# Ignore informational headers:
47+
return if status >= 100 && status < 200
48+
4349
@response.status = Integer(value)
4450
elsif key == PROTOCOL
4551
@response.protocol = value

lib/async/http/protocol/request.rb

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def hijack?
2525
false
2626
end
2727

28+
def write_interim_response(response)
29+
end
30+
2831
def peer
2932
if connection = self.connection
3033
connection.peer

0 commit comments

Comments
 (0)