Skip to content

Commit 2c26e49

Browse files
committed
Add static into-parts for incoming messages; deprecate consume
Closes #102. See discussion in that issue for the motivation and design of this change.
1 parent 37b91f4 commit 2c26e49

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

imports.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ the parent <a href="#incoming_request"><code>incoming-request</code></a> is drop
974974
<h4><a name="method_incoming_request.consume"></a><code>[method]incoming-request.consume: func</code></h4>
975975
<p>Gives the <a href="#incoming_body"><code>incoming-body</code></a> associated with this request. Will only
976976
return success at most once, and subsequent calls will return error.</p>
977+
<p>Deprecated in favor of <code>into-parts</code>.</p>
977978
<h5>Params</h5>
978979
<ul>
979980
<li><a name="method_incoming_request.consume.self"></a><code>self</code>: borrow&lt;<a href="#incoming_request"><a href="#incoming_request"><code>incoming-request</code></a></a>&gt;</li>
@@ -982,6 +983,17 @@ return success at most once, and subsequent calls will return error.</p>
982983
<ul>
983984
<li><a name="method_incoming_request.consume.0"></a> result&lt;own&lt;<a href="#incoming_body"><a href="#incoming_body"><code>incoming-body</code></a></a>&gt;&gt;</li>
984985
</ul>
986+
<h4><a name="static_incoming_request.into_parts"></a><code>[static]incoming-request.into-parts: func</code></h4>
987+
<p>Decompose the incoming request into its component parts.</p>
988+
<p>All resources returned by this function are owned.</p>
989+
<h5>Params</h5>
990+
<ul>
991+
<li><a name="static_incoming_request.into_parts.response"></a><code>response</code>: own&lt;<a href="#incoming_request"><a href="#incoming_request"><code>incoming-request</code></a></a>&gt;</li>
992+
</ul>
993+
<h5>Return values</h5>
994+
<ul>
995+
<li><a name="static_incoming_request.into_parts.0"></a> (<a href="#method"><a href="#method"><code>method</code></a></a>, option&lt;<code>string</code>&gt;, option&lt;<a href="#scheme"><a href="#scheme"><code>scheme</code></a></a>&gt;, option&lt;<code>string</code>&gt;, own&lt;<a href="#headers"><a href="#headers"><code>headers</code></a></a>&gt;, own&lt;<a href="#incoming_body"><a href="#incoming_body"><code>incoming-body</code></a></a>&gt;)</li>
996+
</ul>
985997
<h4><a name="constructor_outgoing_request"></a><code>[constructor]outgoing-request: func</code></h4>
986998
<p>Construct a new <a href="#outgoing_request"><code>outgoing-request</code></a> with a default <a href="#method"><code>method</code></a> of <code>GET</code>, and
987999
<code>none</code> values for <code>path-with-query</code>, <a href="#scheme"><code>scheme</code></a>, and <code>authority</code>.</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,17 @@ 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="static_incoming_response.into_parts"></a><code>[static]incoming-response.into-parts: func</code></h4>
1265+
<p>Decompose the incoming response into its component parts.</p>
1266+
<p>All resources returned by this function are owned.</p>
1267+
<h5>Params</h5>
1268+
<ul>
1269+
<li><a name="static_incoming_response.into_parts.response"></a><code>response</code>: own&lt;<a href="#incoming_response"><a href="#incoming_response"><code>incoming-response</code></a></a>&gt;</li>
1270+
</ul>
1271+
<h5>Return values</h5>
1272+
<ul>
1273+
<li><a name="static_incoming_response.into_parts.0"></a> (<a href="#status_code"><a href="#status_code"><code>status-code</code></a></a>, own&lt;<a href="#headers"><a href="#headers"><code>headers</code></a></a>&gt;, own&lt;<a href="#incoming_body"><a href="#incoming_body"><code>incoming-body</code></a></a>&gt;)</li>
1274+
</ul>
12511275
<h4><a name="method_incoming_body.stream"></a><code>[method]incoming-body.stream: func</code></h4>
12521276
<p>Returns the contents of the body, as a stream of bytes.</p>
12531277
<p>Returns success on first call: the stream representing the contents

proxy.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ the parent <a href="#incoming_request"><code>incoming-request</code></a> is drop
909909
<h4><a name="method_incoming_request.consume"></a><code>[method]incoming-request.consume: func</code></h4>
910910
<p>Gives the <a href="#incoming_body"><code>incoming-body</code></a> associated with this request. Will only
911911
return success at most once, and subsequent calls will return error.</p>
912+
<p>Deprecated in favor of <code>into-parts</code>.</p>
912913
<h5>Params</h5>
913914
<ul>
914915
<li><a name="method_incoming_request.consume.self"></a><code>self</code>: borrow&lt;<a href="#incoming_request"><a href="#incoming_request"><code>incoming-request</code></a></a>&gt;</li>
@@ -917,6 +918,17 @@ return success at most once, and subsequent calls will return error.</p>
917918
<ul>
918919
<li><a name="method_incoming_request.consume.0"></a> result&lt;own&lt;<a href="#incoming_body"><a href="#incoming_body"><code>incoming-body</code></a></a>&gt;&gt;</li>
919920
</ul>
921+
<h4><a name="static_incoming_request.into_parts"></a><code>[static]incoming-request.into-parts: func</code></h4>
922+
<p>Decompose the incoming request into its component parts.</p>
923+
<p>All resources returned by this function are owned.</p>
924+
<h5>Params</h5>
925+
<ul>
926+
<li><a name="static_incoming_request.into_parts.response"></a><code>response</code>: own&lt;<a href="#incoming_request"><a href="#incoming_request"><code>incoming-request</code></a></a>&gt;</li>
927+
</ul>
928+
<h5>Return values</h5>
929+
<ul>
930+
<li><a name="static_incoming_request.into_parts.0"></a> (<a href="#method"><a href="#method"><code>method</code></a></a>, option&lt;<code>string</code>&gt;, option&lt;<a href="#scheme"><a href="#scheme"><code>scheme</code></a></a>&gt;, option&lt;<code>string</code>&gt;, own&lt;<a href="#headers"><a href="#headers"><code>headers</code></a></a>&gt;, own&lt;<a href="#incoming_body"><a href="#incoming_body"><code>incoming-body</code></a></a>&gt;)</li>
931+
</ul>
920932
<h4><a name="constructor_outgoing_request"></a><code>[constructor]outgoing-request: func</code></h4>
921933
<p>Construct a new <a href="#outgoing_request"><code>outgoing-request</code></a> with a default <a href="#method"><code>method</code></a> of <code>GET</code>, and
922934
<code>none</code> values for <code>path-with-query</code>, <a href="#scheme"><code>scheme</code></a>, and <code>authority</code>.</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,17 @@ 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="static_incoming_response.into_parts"></a><code>[static]incoming-response.into-parts: func</code></h4>
1200+
<p>Decompose the incoming response into its component parts.</p>
1201+
<p>All resources returned by this function are owned.</p>
1202+
<h5>Params</h5>
1203+
<ul>
1204+
<li><a name="static_incoming_response.into_parts.response"></a><code>response</code>: own&lt;<a href="#incoming_response"><a href="#incoming_response"><code>incoming-response</code></a></a>&gt;</li>
1205+
</ul>
1206+
<h5>Return values</h5>
1207+
<ul>
1208+
<li><a name="static_incoming_response.into_parts.0"></a> (<a href="#status_code"><a href="#status_code"><code>status-code</code></a></a>, own&lt;<a href="#headers"><a href="#headers"><code>headers</code></a></a>&gt;, own&lt;<a href="#incoming_body"><a href="#incoming_body"><code>incoming-body</code></a></a>&gt;)</li>
1209+
</ul>
11861210
<h4><a name="method_incoming_body.stream"></a><code>[method]incoming-body.stream: func</code></h4>
11871211
<p>Returns the contents of the body, as a stream of bytes.</p>
11881212
<p>Returns success on first call: the stream representing the contents

wit/types.wit

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,23 @@ interface types {
244244

245245
/// Gives the `incoming-body` associated with this request. Will only
246246
/// return success at most once, and subsequent calls will return error.
247+
///
248+
/// Deprecated in favor of `into-parts`.
247249
consume: func() -> result<incoming-body>;
250+
251+
/// Decompose the incoming request into its component parts.
252+
///
253+
/// All resources returned by this function are owned.
254+
into-parts: static func(
255+
response: incoming-request
256+
) -> tuple<
257+
method,
258+
option<string>, // path-with-query
259+
option<scheme>,
260+
option<string>, // authority
261+
headers,
262+
incoming-body
263+
>;
248264
}
249265

250266
/// Represents an outgoing HTTP Request.
@@ -391,7 +407,16 @@ interface types {
391407

392408
/// Returns the incoming body. May be called at most once. Returns error
393409
/// if called additional times.
410+
///
411+
/// Deprecated in favor of `into-parts`.
394412
consume: func() -> result<incoming-body>;
413+
414+
/// Decompose the incoming response into its component parts.
415+
///
416+
/// All resources returned by this function are owned.
417+
into-parts: static func(
418+
response: incoming-response
419+
) -> tuple<status-code, headers, incoming-body>;
395420
}
396421

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

0 commit comments

Comments
 (0)