Skip to content

Commit fece948

Browse files
Pat Hickeyelliottt
andcommitted
all child fields are immutable, add header-error.immutable error
and update the doc strings throughout to specify which give a mutable fields and which give an immutable fields. also, add missed text that a future-trailers gives a child resource fields Co-authored-by: Trevor Elliott <telliott@fastly.com>
1 parent 8db6763 commit fece948

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

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)