Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasi-http: Use borrow syntax for borrowed resources #7161

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/test-programs/wasi-http-proxy-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct T;
impl bindings::exports::wasi::http::incoming_handler::Guest for T {
fn handle(_request: IncomingRequest, outparam: ResponseOutparam) {
let hdrs = bindings::wasi::http::types::Headers::new(&[]);
let resp = bindings::wasi::http::types::OutgoingResponse::new(200, hdrs);
let resp = bindings::wasi::http::types::OutgoingResponse::new(200, &hdrs);
let body = resp.write().expect("outgoing response");

bindings::wasi::http::types::ResponseOutparam::set(outparam, Ok(resp));
Expand Down
2 changes: 1 addition & 1 deletion crates/test-programs/wasi-http-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn request(
Some(path_with_query),
Some(&scheme),
Some(authority),
headers,
&headers,
);

let outgoing_body = request
Expand Down
1 change: 0 additions & 1 deletion crates/wasi-http/src/types_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ impl<T: WasiHttpView> crate::bindings::http::types::HostOutgoingResponse for T {
headers: Resource<Headers>,
) -> wasmtime::Result<Resource<HostOutgoingResponse>> {
let fields = get_fields_mut(self.table(), &headers)?.clone();
self.table().delete_resource(headers)?;

let id = self.table().push_resource(HostOutgoingResponse {
status,
Expand Down
4 changes: 2 additions & 2 deletions crates/wasi-http/wit/deps/http/incoming-handler.wit
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface incoming-handler {
// critical path, since there is no return value, there is no way to report
// its success or failure.
handle: func(
request: /* own */ incoming-request,
response-out: /* own */ response-outparam
request: incoming-request,
response-out: response-outparam
)
}
2 changes: 1 addition & 1 deletion crates/wasi-http/wit/deps/http/outgoing-handler.wit
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface outgoing-handler {
// Consumes the outgoing-request. Gives an error if the outgoing-request
// is invalid or cannot be satisfied by this handler.
handle: func(
request: /* own */ outgoing-request,
request: outgoing-request,
options: option<request-options>
) -> result<future-incoming-response, error>
}
16 changes: 8 additions & 8 deletions crates/wasi-http/wit/deps/http/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ interface types {
// Will return the input-stream child at most once. If called more than
// once, subsequent calls will return error.

consume: func() -> result< /* own */ incoming-body>
consume: func() -> result<incoming-body>
}

resource outgoing-request {
Expand All @@ -96,7 +96,7 @@ interface types {
path-with-query: option<string>,
scheme: option<scheme>,
authority: option<string>,
headers: /* borrow */ headers
headers: borrow<headers>
)

// Will return the outgoing-body child at most once. If called more than
Expand Down Expand Up @@ -127,7 +127,7 @@ interface types {
// (the `wasi:http/handler` interface used for both incoming and outgoing can
// simply return a `stream`).
resource response-outparam {
set: static func(param: /* own */ response-outparam, response: result< /* own */ outgoing-response, error>)
set: static func(param: response-outparam, response: result<outgoing-response, error>)
}

// This type corresponds to the HTTP standard Status Code.
Expand All @@ -148,7 +148,7 @@ interface types {
// May be called at most once. returns error if called additional times.
// TODO: make incoming-request-consume work the same way, giving a child
// incoming-body.
consume: func() -> result</* own */ incoming-body>
consume: func() -> result<incoming-body>
}

resource incoming-body {
Expand All @@ -160,7 +160,7 @@ interface types {

// takes ownership of incoming-body. this will trap if the
// incoming-body-stream child is still alive!
finish: static func(this: /* own */ incoming-body) ->
finish: static func(this: incoming-body) ->
/* transitive child of the incoming-response of incoming-body */ future-trailers
}

Expand All @@ -174,11 +174,11 @@ interface types {
}

resource outgoing-response {
constructor(status-code: status-code, headers: /* borrow */ headers)
constructor(status-code: status-code, headers: borrow<headers>)

/// Will give the child outgoing-response at most once. subsequent calls will
/// return an error.
write: func() -> result</* own */ outgoing-body>
write: func() -> result<outgoing-body>
}

resource outgoing-body {
Expand All @@ -190,7 +190,7 @@ interface types {
/// called to signal that the response is complete. If the `outgoing-body` is
/// dropped without calling `outgoing-body-finalize`, the implementation
/// should treat the body as corrupted.
finish: static func(this: /* own */ outgoing-body, trailers: /* own */ option<trailers>)
finish: static func(this: outgoing-body, trailers: option<trailers>)
}

/// The following block defines a special resource type used by the
Expand Down
4 changes: 2 additions & 2 deletions crates/wasi/wit/deps/http/incoming-handler.wit
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface incoming-handler {
// critical path, since there is no return value, there is no way to report
// its success or failure.
handle: func(
request: /* own */ incoming-request,
response-out: /* own */ response-outparam
request: incoming-request,
response-out: response-outparam
)
}
2 changes: 1 addition & 1 deletion crates/wasi/wit/deps/http/outgoing-handler.wit
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface outgoing-handler {
// Consumes the outgoing-request. Gives an error if the outgoing-request
// is invalid or cannot be satisfied by this handler.
handle: func(
request: /* own */ outgoing-request,
request: outgoing-request,
options: option<request-options>
) -> result<future-incoming-response, error>
}
16 changes: 8 additions & 8 deletions crates/wasi/wit/deps/http/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ interface types {
// Will return the input-stream child at most once. If called more than
// once, subsequent calls will return error.

consume: func() -> result< /* own */ incoming-body>
consume: func() -> result<incoming-body>
}

resource outgoing-request {
Expand All @@ -96,7 +96,7 @@ interface types {
path-with-query: option<string>,
scheme: option<scheme>,
authority: option<string>,
headers: /* borrow */ headers
headers: borrow<headers>
)

// Will return the outgoing-body child at most once. If called more than
Expand Down Expand Up @@ -127,7 +127,7 @@ interface types {
// (the `wasi:http/handler` interface used for both incoming and outgoing can
// simply return a `stream`).
resource response-outparam {
set: static func(param: /* own */ response-outparam, response: result< /* own */ outgoing-response, error>)
set: static func(param: response-outparam, response: result<outgoing-response, error>)
}

// This type corresponds to the HTTP standard Status Code.
Expand All @@ -148,7 +148,7 @@ interface types {
// May be called at most once. returns error if called additional times.
// TODO: make incoming-request-consume work the same way, giving a child
// incoming-body.
consume: func() -> result</* own */ incoming-body>
consume: func() -> result<incoming-body>
}

resource incoming-body {
Expand All @@ -160,7 +160,7 @@ interface types {

// takes ownership of incoming-body. this will trap if the
// incoming-body-stream child is still alive!
finish: static func(this: /* own */ incoming-body) ->
finish: static func(this: incoming-body) ->
/* transitive child of the incoming-response of incoming-body */ future-trailers
}

Expand All @@ -174,11 +174,11 @@ interface types {
}

resource outgoing-response {
constructor(status-code: status-code, headers: /* borrow */ headers)
constructor(status-code: status-code, headers: borrow<headers>)

/// Will give the child outgoing-response at most once. subsequent calls will
/// return an error.
write: func() -> result</* own */ outgoing-body>
write: func() -> result<outgoing-body>
}

resource outgoing-body {
Expand All @@ -190,7 +190,7 @@ interface types {
/// called to signal that the response is complete. If the `outgoing-body` is
/// dropped without calling `outgoing-body-finalize`, the implementation
/// should treat the body as corrupted.
finish: static func(this: /* own */ outgoing-body, trailers: /* own */ option<trailers>)
finish: static func(this: outgoing-body, trailers: option<trailers>)
}

/// The following block defines a special resource type used by the
Expand Down