You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The value of this uni-directional flow is that it is natural for the stream to be taken out of the scope imposed by the nested `call(request)` model. However, the user must explicitly close the stream, since it's no longer scoped to the client and/or server.
192
+
193
+
## Interim Response Handling
194
+
195
+
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.
# @attribute [String | Array(String) | Nil] the request protocol, usually empty, but occasionally `"websocket"` or `"webtransport"`. In HTTP/1, it is used to request a connection upgrade, and in HTTP/2 it is used to indicate a specfic protocol for the stream.
61
62
attr_accessor:protocol
62
63
64
+
# @attribute [Proc] a callback which is called when an interim response is received.
65
+
attr_accessor:interim_response
66
+
63
67
# Send the request to the given connection.
64
68
defcall(connection)
65
69
connection.call(self)
66
70
end
67
71
72
+
# Send an interim response back to the origin of this request, if possible.
73
+
defsend_interim_response(status,headers)
74
+
@interim_response&.call(status,headers)
75
+
end
76
+
77
+
defon_interim_response(&block)
78
+
ifinterim_response=@interim_response
79
+
@interim_response=->(status,headers)do
80
+
block.call(status,headers)
81
+
interim_response.call(status,headers)
82
+
end
83
+
else
84
+
@interim_response=block
85
+
end
86
+
end
87
+
68
88
# Whether this is a HEAD request: no body is expected in the response.
69
89
defhead?
70
90
@method == Methods::HEAD
@@ -81,11 +101,11 @@ def connect?
81
101
# @parameter path [String] The path, e.g. `"/index.html"`, `"/search?q=hello"`, etc.
82
102
# @parameter headers [Hash] The headers, e.g. `{"accept" => "text/html"}`, etc.
83
103
# @parameter body [String | Array(String) | Body::Readable] The body, e.g. `"Hello, World!"`, etc. See {Body::Buffered.wrap} for more information about .
The `Request` class now exposes a `#interim_response` attribute which can be used to handle interim responses both on the client side and server side.
21
+
22
+
On the client side, you can pass a callback using the `interim_response` keyword argument which will be invoked whenever an interim response is received:
0 commit comments