@@ -117,6 +117,10 @@ interface types {
117
117
/// This error indicates that a forbidden `field-key` was used when trying
118
118
/// to set a header in a `fields` .
119
119
forbidden ,
120
+
121
+ /// This error indicates that the operation on the `fields` was not
122
+ /// permitted because the fields are immutable.
123
+ immutable ,
120
124
}
121
125
122
126
/// Field keys are always strings.
@@ -130,13 +134,24 @@ interface types {
130
134
/// This following block defines the `fields` resource which corresponds to
131
135
/// HTTP standard Fields. Fields are a common representation used for both
132
136
/// 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` .
133
144
resource fields {
134
145
135
146
/// Construct an empty HTTP Fields.
147
+ ///
148
+ /// The resulting `fields` is mutable.
136
149
constructor ();
137
150
138
151
/// Construct an HTTP Fields.
139
152
///
153
+ /// The resulting `fields` is mutable.
154
+ ///
140
155
/// The list represents each key-value pair in the Fields. Keys
141
156
/// which have multiple values are represented by multiple entries in this
142
157
/// list with the same key.
@@ -157,14 +172,20 @@ interface types {
157
172
158
173
/// Set all of the values for a key. Clears any existing values for that
159
174
/// key, if they have been set.
175
+ ///
176
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
160
177
set : func (name : field-key , value : list <field-value >) -> result <_ , header-error >;
161
178
162
179
/// Delete all values for a key. Does nothing if no values for the key
163
180
/// exist.
181
+ ///
182
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
164
183
delete : func (name : field-key ) -> result <_ , header-error >;
165
184
166
185
/// Append a value for a key. Does not change or delete any existing
167
186
/// values for that key.
187
+ ///
188
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
168
189
append : func (name : field-key , value : field-value ) -> result <_ , header-error >;
169
190
170
191
/// Retrieve the full set of keys and values in the Fields. Like the
@@ -176,7 +197,8 @@ interface types {
176
197
entries : func () -> list <tuple <field-key ,field-value >>;
177
198
178
199
/// 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.
180
202
clone : func () -> fields ;
181
203
}
182
204
@@ -201,7 +223,10 @@ interface types {
201
223
/// Returns the authority from the request, if it was present.
202
224
authority : func () -> option <string >;
203
225
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` .
205
230
///
206
231
/// The `headers` returned are a child resource: it must be dropped before
207
232
/// the parent `incoming-request` is dropped. Dropping this
@@ -272,6 +297,9 @@ interface types {
272
297
273
298
/// Get the headers associated with the Request.
274
299
///
300
+ /// The returned `headers` resource is immutable: `set` , `append` , and
301
+ /// `delete` operations will fail with `header-error.immutable` .
302
+ ///
275
303
/// This headers resource is a child: it must be dropped before the parent
276
304
/// `outgoing-request` is dropped, or its ownership is transfered to
277
305
/// another component by e.g. `outgoing-handler.handle` .
@@ -344,6 +372,12 @@ interface types {
344
372
status : func () -> status-code ;
345
373
346
374
/// 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.
347
381
headers : func () -> headers ;
348
382
349
383
/// Returns the incoming body. May be called at most once. Returns error
@@ -405,6 +439,11 @@ interface types {
405
439
/// as well as any trailers, were received successfully, or that an error
406
440
/// occured receiving them. The optional `trailers` indicates whether or not
407
441
/// 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.
408
447
get : func () -> option <result <option <trailers >, error-code >>;
409
448
}
410
449
@@ -427,6 +466,9 @@ interface types {
427
466
428
467
/// Get the headers associated with the Request.
429
468
///
469
+ /// The returned `headers` resource is immutable: `set` , `append` , and
470
+ /// `delete` operations will fail with `header-error.immutable` .
471
+ ///
430
472
/// This headers resource is a child: it must be dropped before the parent
431
473
/// `outgoing-request` is dropped, or its ownership is transfered to
432
474
/// another component by e.g. `outgoing-handler.handle` .
0 commit comments