Skip to content

Commit 55a4754

Browse files
committed
Add take-headers to get owned headers from incoming messages
Closes #102. See discussion in that issue for the motivation and design of this change.
1 parent 37b91f4 commit 55a4754

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

imports.md

+25
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,18 @@ the parent <a href="#incoming_request"><code>incoming-request</code></a> is drop
971971
<ul>
972972
<li><a name="method_incoming_request.headers.0"></a> own&lt;<a href="#headers"><a href="#headers"><code>headers</code></a></a>&gt;</li>
973973
</ul>
974+
<h4><a name="method_incoming_request.take_headers"></a><code>[method]incoming-request.take-headers: func</code></h4>
975+
<p>Gives the <a href="#headers"><code>headers</code></a> associated with this request as an owned resource.
976+
Will only return success at most once, and subsequent calls will return
977+
error.</p>
978+
<h5>Params</h5>
979+
<ul>
980+
<li><a name="method_incoming_request.take_headers.self"></a><code>self</code>: borrow&lt;<a href="#incoming_request"><a href="#incoming_request"><code>incoming-request</code></a></a>&gt;</li>
981+
</ul>
982+
<h5>Return values</h5>
983+
<ul>
984+
<li><a name="method_incoming_request.take_headers.0"></a> result&lt;own&lt;<a href="#headers"><a href="#headers"><code>headers</code></a></a>&gt;&gt;</li>
985+
</ul>
974986
<h4><a name="method_incoming_request.consume"></a><code>[method]incoming-request.consume: func</code></h4>
975987
<p>Gives the <a href="#incoming_body"><code>incoming-body</code></a> associated with this request. Will only
976988
return success at most once, and subsequent calls will return error.</p>
@@ -1240,6 +1252,7 @@ implementation determine how to respond with an HTTP error response.</p>
12401252
<h4><a name="method_incoming_response.consume"></a><code>[method]incoming-response.consume: func</code></h4>
12411253
<p>Returns the incoming body. May be called at most once. Returns error
12421254
if called additional times.</p>
1255+
<p>Deprecated in favor of <code>into-parts</code>.</p>
12431256
<h5>Params</h5>
12441257
<ul>
12451258
<li><a name="method_incoming_response.consume.self"></a><code>self</code>: borrow&lt;<a href="#incoming_response"><a href="#incoming_response"><code>incoming-response</code></a></a>&gt;</li>
@@ -1248,6 +1261,18 @@ if called additional times.</p>
12481261
<ul>
12491262
<li><a name="method_incoming_response.consume.0"></a> result&lt;own&lt;<a href="#incoming_body"><a href="#incoming_body"><code>incoming-body</code></a></a>&gt;&gt;</li>
12501263
</ul>
1264+
<h4><a name="method_incoming_response.take_headers"></a><code>[method]incoming-response.take-headers: func</code></h4>
1265+
<p>Returns the <a href="#headers"><code>headers</code></a> associated with this response as an owned
1266+
resource. Will only return success at most once, and subsequent calls
1267+
will return error.</p>
1268+
<h5>Params</h5>
1269+
<ul>
1270+
<li><a name="method_incoming_response.take_headers.self"></a><code>self</code>: borrow&lt;<a href="#incoming_response"><a href="#incoming_response"><code>incoming-response</code></a></a>&gt;</li>
1271+
</ul>
1272+
<h5>Return values</h5>
1273+
<ul>
1274+
<li><a name="method_incoming_response.take_headers.0"></a> result&lt;own&lt;<a href="#headers"><a href="#headers"><code>headers</code></a></a>&gt;&gt;</li>
1275+
</ul>
12511276
<h4><a name="method_incoming_body.stream"></a><code>[method]incoming-body.stream: func</code></h4>
12521277
<p>Returns the contents of the body, as a stream of bytes.</p>
12531278
<p>Returns success on first call: the stream representing the contents

proxy.md

+25
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,18 @@ the parent <a href="#incoming_request"><code>incoming-request</code></a> is drop
906906
<ul>
907907
<li><a name="method_incoming_request.headers.0"></a> own&lt;<a href="#headers"><a href="#headers"><code>headers</code></a></a>&gt;</li>
908908
</ul>
909+
<h4><a name="method_incoming_request.take_headers"></a><code>[method]incoming-request.take-headers: func</code></h4>
910+
<p>Gives the <a href="#headers"><code>headers</code></a> associated with this request as an owned resource.
911+
Will only return success at most once, and subsequent calls will return
912+
error.</p>
913+
<h5>Params</h5>
914+
<ul>
915+
<li><a name="method_incoming_request.take_headers.self"></a><code>self</code>: borrow&lt;<a href="#incoming_request"><a href="#incoming_request"><code>incoming-request</code></a></a>&gt;</li>
916+
</ul>
917+
<h5>Return values</h5>
918+
<ul>
919+
<li><a name="method_incoming_request.take_headers.0"></a> result&lt;own&lt;<a href="#headers"><a href="#headers"><code>headers</code></a></a>&gt;&gt;</li>
920+
</ul>
909921
<h4><a name="method_incoming_request.consume"></a><code>[method]incoming-request.consume: func</code></h4>
910922
<p>Gives the <a href="#incoming_body"><code>incoming-body</code></a> associated with this request. Will only
911923
return success at most once, and subsequent calls will return error.</p>
@@ -1175,6 +1187,7 @@ implementation determine how to respond with an HTTP error response.</p>
11751187
<h4><a name="method_incoming_response.consume"></a><code>[method]incoming-response.consume: func</code></h4>
11761188
<p>Returns the incoming body. May be called at most once. Returns error
11771189
if called additional times.</p>
1190+
<p>Deprecated in favor of <code>into-parts</code>.</p>
11781191
<h5>Params</h5>
11791192
<ul>
11801193
<li><a name="method_incoming_response.consume.self"></a><code>self</code>: borrow&lt;<a href="#incoming_response"><a href="#incoming_response"><code>incoming-response</code></a></a>&gt;</li>
@@ -1183,6 +1196,18 @@ if called additional times.</p>
11831196
<ul>
11841197
<li><a name="method_incoming_response.consume.0"></a> result&lt;own&lt;<a href="#incoming_body"><a href="#incoming_body"><code>incoming-body</code></a></a>&gt;&gt;</li>
11851198
</ul>
1199+
<h4><a name="method_incoming_response.take_headers"></a><code>[method]incoming-response.take-headers: func</code></h4>
1200+
<p>Returns the <a href="#headers"><code>headers</code></a> associated with this response as an owned
1201+
resource. Will only return success at most once, and subsequent calls
1202+
will return error.</p>
1203+
<h5>Params</h5>
1204+
<ul>
1205+
<li><a name="method_incoming_response.take_headers.self"></a><code>self</code>: borrow&lt;<a href="#incoming_response"><a href="#incoming_response"><code>incoming-response</code></a></a>&gt;</li>
1206+
</ul>
1207+
<h5>Return values</h5>
1208+
<ul>
1209+
<li><a name="method_incoming_response.take_headers.0"></a> result&lt;own&lt;<a href="#headers"><a href="#headers"><code>headers</code></a></a>&gt;&gt;</li>
1210+
</ul>
11861211
<h4><a name="method_incoming_body.stream"></a><code>[method]incoming-body.stream: func</code></h4>
11871212
<p>Returns the contents of the body, as a stream of bytes.</p>
11881213
<p>Returns success on first call: the stream representing the contents

wit/types.wit

+10
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ interface types {
242242
/// `incoming-request` before all children are dropped will trap.
243243
headers: func() -> headers;
244244

245+
/// Gives the `headers` associated with this request as an owned resource.
246+
/// Will only return success at most once, and subsequent calls will return
247+
/// error.
248+
take-headers: func() -> result<headers>;
249+
245250
/// Gives the `incoming-body` associated with this request. Will only
246251
/// return success at most once, and subsequent calls will return error.
247252
consume: func() -> result<incoming-body>;
@@ -392,6 +397,11 @@ interface types {
392397
/// Returns the incoming body. May be called at most once. Returns error
393398
/// if called additional times.
394399
consume: func() -> result<incoming-body>;
400+
401+
/// Returns the `headers` associated with this response as an owned
402+
/// resource. Will only return success at most once, and subsequent calls
403+
/// will return error.
404+
take-headers: func() -> result<headers>;
395405
}
396406

397407
/// Represents an incoming HTTP Request or Response's Body.

0 commit comments

Comments
 (0)