Skip to content

Commit e181913

Browse files
authored
Merge pull request #70 from WebAssembly/pch/immutable_headers
all child fields are immutable, add header-error.immutable error
2 parents 8db6763 + 5731080 commit e181913

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed

proxy.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,11 @@ syntactically invalid when used with an operation that sets headers in a
760760
<p>This error indicates that a forbidden `field-key` was used when trying
761761
to set a header in a `fields`.
762762
</li>
763+
<li>
764+
<p><a name="header_error.immutable"><code>immutable</code></a></p>
765+
<p>This error indicates that the operation on the `fields` was not
766+
permitted because the fields are immutable.
767+
</li>
763768
</ul>
764769
<h4><a name="field_key"><code>type field-key</code></a></h4>
765770
<p><code>string</code></p>
@@ -810,12 +815,14 @@ are http-related errors.</p>
810815
</ul>
811816
<h4><a name="constructor_fields"><code>[constructor]fields: func</code></a></h4>
812817
<p>Construct an empty HTTP Fields.</p>
818+
<p>The resulting <a href="#fields"><code>fields</code></a> is mutable.</p>
813819
<h5>Return values</h5>
814820
<ul>
815821
<li><a name="constructor_fields.0"></a> own&lt;<a href="#fields"><a href="#fields"><code>fields</code></a></a>&gt;</li>
816822
</ul>
817823
<h4><a name="static_fields.from_list"><code>[static]fields.from-list: func</code></a></h4>
818824
<p>Construct an HTTP Fields.</p>
825+
<p>The resulting <a href="#fields"><code>fields</code></a> is mutable.</p>
819826
<p>The list represents each key-value pair in the Fields. Keys
820827
which have multiple values are represented by multiple entries in this
821828
list with the same key.</p>
@@ -847,6 +854,7 @@ syntactically invalid, or if a header was forbidden.</p>
847854
<h4><a name="method_fields.set"><code>[method]fields.set: func</code></a></h4>
848855
<p>Set all of the values for a key. Clears any existing values for that
849856
key, if they have been set.</p>
857+
<p>Fails with <code>header-error.immutable</code> if the <a href="#fields"><code>fields</code></a> are immutable.</p>
850858
<h5>Params</h5>
851859
<ul>
852860
<li><a name="method_fields.set.self"><code>self</code></a>: borrow&lt;<a href="#fields"><a href="#fields"><code>fields</code></a></a>&gt;</li>
@@ -860,6 +868,7 @@ key, if they have been set.</p>
860868
<h4><a name="method_fields.delete"><code>[method]fields.delete: func</code></a></h4>
861869
<p>Delete all values for a key. Does nothing if no values for the key
862870
exist.</p>
871+
<p>Fails with <code>header-error.immutable</code> if the <a href="#fields"><code>fields</code></a> are immutable.</p>
863872
<h5>Params</h5>
864873
<ul>
865874
<li><a name="method_fields.delete.self"><code>self</code></a>: borrow&lt;<a href="#fields"><a href="#fields"><code>fields</code></a></a>&gt;</li>
@@ -872,6 +881,7 @@ exist.</p>
872881
<h4><a name="method_fields.append"><code>[method]fields.append: func</code></a></h4>
873882
<p>Append a value for a key. Does not change or delete any existing
874883
values for that key.</p>
884+
<p>Fails with <code>header-error.immutable</code> if the <a href="#fields"><code>fields</code></a> are immutable.</p>
875885
<h5>Params</h5>
876886
<ul>
877887
<li><a name="method_fields.append.self"><code>self</code></a>: borrow&lt;<a href="#fields"><a href="#fields"><code>fields</code></a></a>&gt;</li>
@@ -898,7 +908,8 @@ list with the same key.</p>
898908
</ul>
899909
<h4><a name="method_fields.clone"><code>[method]fields.clone: func</code></a></h4>
900910
<p>Make a deep copy of the Fields. Equivelant in behavior to calling the
901-
<a href="#fields"><code>fields</code></a> constructor on the return value of <code>entries</code></p>
911+
<a href="#fields"><code>fields</code></a> constructor on the return value of <code>entries</code>. The resulting
912+
<a href="#fields"><code>fields</code></a> is mutable.</p>
902913
<h5>Params</h5>
903914
<ul>
904915
<li><a name="method_fields.clone.self"><code>self</code></a>: borrow&lt;<a href="#fields"><a href="#fields"><code>fields</code></a></a>&gt;</li>
@@ -948,7 +959,9 @@ list with the same key.</p>
948959
<li><a name="method_incoming_request.authority.0"></a> option&lt;<code>string</code>&gt;</li>
949960
</ul>
950961
<h4><a name="method_incoming_request.headers"><code>[method]incoming-request.headers: func</code></a></h4>
951-
<p>Returns the <a href="#headers"><code>headers</code></a> from the request.</p>
962+
<p>Get the <a href="#headers"><code>headers</code></a> associated with the request.</p>
963+
<p>The returned <a href="#headers"><code>headers</code></a> resource is immutable: <code>set</code>, <code>append</code>, and
964+
<code>delete</code> operations will fail with <code>header-error.immutable</code>.</p>
952965
<p>The <a href="#headers"><code>headers</code></a> returned are a child resource: it must be dropped before
953966
the parent <a href="#incoming_request"><code>incoming-request</code></a> is dropped. Dropping this
954967
<a href="#incoming_request"><code>incoming-request</code></a> before all children are dropped will trap.</p>
@@ -1102,6 +1115,8 @@ not a syntactically valid uri authority.</p>
11021115
</ul>
11031116
<h4><a name="method_outgoing_request.headers"><code>[method]outgoing-request.headers: func</code></a></h4>
11041117
<p>Get the headers associated with the Request.</p>
1118+
<p>The returned <a href="#headers"><code>headers</code></a> resource is immutable: <code>set</code>, <code>append</code>, and
1119+
<code>delete</code> operations will fail with <code>header-error.immutable</code>.</p>
11051120
<p>This headers resource is a child: it must be dropped before the parent
11061121
<a href="#outgoing_request"><code>outgoing-request</code></a> is dropped, or its ownership is transfered to
11071122
another component by e.g. <code>outgoing-handler.handle</code>.</p>
@@ -1212,6 +1227,10 @@ implementation determine how to respond with an HTTP error response.</p>
12121227
</ul>
12131228
<h4><a name="method_incoming_response.headers"><code>[method]incoming-response.headers: func</code></a></h4>
12141229
<p>Returns the headers from the incoming response.</p>
1230+
<p>The returned <a href="#headers"><code>headers</code></a> resource is immutable: <code>set</code>, <code>append</code>, and
1231+
<code>delete</code> operations will fail with <code>header-error.immutable</code>.</p>
1232+
<p>This headers resource is a child: it must be dropped before the parent
1233+
<a href="#incoming_response"><code>incoming-response</code></a> is dropped.</p>
12151234
<h5>Params</h5>
12161235
<ul>
12171236
<li><a name="method_incoming_response.headers.self"><code>self</code></a>: borrow&lt;<a href="#incoming_response"><a href="#incoming_response"><code>incoming-response</code></a></a>&gt;</li>
@@ -1284,6 +1303,10 @@ once the future is ready.</p>
12841303
as well as any trailers, were received successfully, or that an error
12851304
occured receiving them. The optional <a href="#trailers"><code>trailers</code></a> indicates whether or not
12861305
trailers were present in the body.</p>
1306+
<p>When some <a href="#trailers"><code>trailers</code></a> are returned by this method, the <a href="#trailers"><code>trailers</code></a>
1307+
resource is immutable, and a child. Use of the <code>set</code>, <code>append</code>, or
1308+
<code>delete</code> methods will return an error, and the resource must be
1309+
dropped before the parent <a href="#future_trailers"><code>future-trailers</code></a> is dropped.</p>
12871310
<h5>Params</h5>
12881311
<ul>
12891312
<li><a name="method_future_trailers.get.self"><code>self</code></a>: borrow&lt;<a href="#future_trailers"><a href="#future_trailers"><code>future-trailers</code></a></a>&gt;</li>
@@ -1331,6 +1354,8 @@ given is not a valid http status code.</p>
13311354
</ul>
13321355
<h4><a name="method_outgoing_response.headers"><code>[method]outgoing-response.headers: func</code></a></h4>
13331356
<p>Get the headers associated with the Request.</p>
1357+
<p>The returned <a href="#headers"><code>headers</code></a> resource is immutable: <code>set</code>, <code>append</code>, and
1358+
<code>delete</code> operations will fail with <code>header-error.immutable</code>.</p>
13341359
<p>This headers resource is a child: it must be dropped before the parent
13351360
<a href="#outgoing_request"><code>outgoing-request</code></a> is dropped, or its ownership is transfered to
13361361
another component by e.g. <code>outgoing-handler.handle</code>.</p>

wit/types.wit

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ interface types {
117117
/// This error indicates that a forbidden `field-key` was used when trying
118118
/// to set a header in a `fields`.
119119
forbidden,
120+
121+
/// This error indicates that the operation on the `fields` was not
122+
/// permitted because the fields are immutable.
123+
immutable,
120124
}
121125

122126
/// Field keys are always strings.
@@ -130,13 +134,24 @@ interface types {
130134
/// This following block defines the `fields` resource which corresponds to
131135
/// HTTP standard Fields. Fields are a common representation used for both
132136
/// Headers and Trailers.
137+
///
138+
/// A `fields` may be mutable or immutable. A `fields` created using the
139+
/// constructor, `from-list`, or `clone` will be mutable, but a `fields`
140+
/// resource given by other means (including, but not limited to,
141+
/// `incoming-request.headers`, `outgoing-request.headers`) might be be
142+
/// immutable. In an immutable fields, the `set`, `append`, and `delete`
143+
/// operations will fail with `header-error.immutable`.
133144
resource fields {
134145

135146
/// Construct an empty HTTP Fields.
147+
///
148+
/// The resulting `fields` is mutable.
136149
constructor();
137150

138151
/// Construct an HTTP Fields.
139152
///
153+
/// The resulting `fields` is mutable.
154+
///
140155
/// The list represents each key-value pair in the Fields. Keys
141156
/// which have multiple values are represented by multiple entries in this
142157
/// list with the same key.
@@ -157,14 +172,20 @@ interface types {
157172

158173
/// Set all of the values for a key. Clears any existing values for that
159174
/// key, if they have been set.
175+
///
176+
/// Fails with `header-error.immutable` if the `fields` are immutable.
160177
set: func(name: field-key, value: list<field-value>) -> result<_, header-error>;
161178

162179
/// Delete all values for a key. Does nothing if no values for the key
163180
/// exist.
181+
///
182+
/// Fails with `header-error.immutable` if the `fields` are immutable.
164183
delete: func(name: field-key) -> result<_, header-error>;
165184

166185
/// Append a value for a key. Does not change or delete any existing
167186
/// values for that key.
187+
///
188+
/// Fails with `header-error.immutable` if the `fields` are immutable.
168189
append: func(name: field-key, value: field-value) -> result<_, header-error>;
169190

170191
/// Retrieve the full set of keys and values in the Fields. Like the
@@ -176,7 +197,8 @@ interface types {
176197
entries: func() -> list<tuple<field-key,field-value>>;
177198

178199
/// Make a deep copy of the Fields. Equivelant in behavior to calling the
179-
/// `fields` constructor on the return value of `entries`
200+
/// `fields` constructor on the return value of `entries`. The resulting
201+
/// `fields` is mutable.
180202
clone: func() -> fields;
181203
}
182204

@@ -201,7 +223,10 @@ interface types {
201223
/// Returns the authority from the request, if it was present.
202224
authority: func() -> option<string>;
203225

204-
/// Returns the `headers` from the request.
226+
/// Get the `headers` associated with the request.
227+
///
228+
/// The returned `headers` resource is immutable: `set`, `append`, and
229+
/// `delete` operations will fail with `header-error.immutable`.
205230
///
206231
/// The `headers` returned are a child resource: it must be dropped before
207232
/// the parent `incoming-request` is dropped. Dropping this
@@ -272,6 +297,9 @@ interface types {
272297

273298
/// Get the headers associated with the Request.
274299
///
300+
/// The returned `headers` resource is immutable: `set`, `append`, and
301+
/// `delete` operations will fail with `header-error.immutable`.
302+
///
275303
/// This headers resource is a child: it must be dropped before the parent
276304
/// `outgoing-request` is dropped, or its ownership is transfered to
277305
/// another component by e.g. `outgoing-handler.handle`.
@@ -344,6 +372,12 @@ interface types {
344372
status: func() -> status-code;
345373

346374
/// Returns the headers from the incoming response.
375+
///
376+
/// The returned `headers` resource is immutable: `set`, `append`, and
377+
/// `delete` operations will fail with `header-error.immutable`.
378+
///
379+
/// This headers resource is a child: it must be dropped before the parent
380+
/// `incoming-response` is dropped.
347381
headers: func() -> headers;
348382

349383
/// Returns the incoming body. May be called at most once. Returns error
@@ -405,6 +439,11 @@ interface types {
405439
/// as well as any trailers, were received successfully, or that an error
406440
/// occured receiving them. The optional `trailers` indicates whether or not
407441
/// trailers were present in the body.
442+
///
443+
/// When some `trailers` are returned by this method, the `trailers`
444+
/// resource is immutable, and a child. Use of the `set`, `append`, or
445+
/// `delete` methods will return an error, and the resource must be
446+
/// dropped before the parent `future-trailers` is dropped.
408447
get: func() -> option<result<option<trailers>, error-code>>;
409448
}
410449

@@ -427,6 +466,9 @@ interface types {
427466

428467
/// Get the headers associated with the Request.
429468
///
469+
/// The returned `headers` resource is immutable: `set`, `append`, and
470+
/// `delete` operations will fail with `header-error.immutable`.
471+
///
430472
/// This headers resource is a child: it must be dropped before the parent
431473
/// `outgoing-request` is dropped, or its ownership is transfered to
432474
/// another component by e.g. `outgoing-handler.handle`.

0 commit comments

Comments
 (0)