Skip to content

Commit 139c409

Browse files
authored
Merge pull request #723 from itowlson/deprecate-http-params
Stop using WASI HTTP params in preparation for deprecation
2 parents d8e15e0 + 130815c commit 139c409

File tree

4 files changed

+14
-40
lines changed

4 files changed

+14
-40
lines changed

crates/http/src/spin.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::{
44
};
55
use anyhow::Result;
66
use async_trait::async_trait;
7-
use http::Uri;
87
use hyper::{Body, Request, Response};
98
use spin_engine::io::ModuleIoRedirects;
109
use std::{net::SocketAddr, str, str::FromStr};
@@ -85,11 +84,10 @@ impl SpinHttpExecutor {
8584
.map(|(k, v)| (k.as_str(), v.as_str()))
8685
.collect();
8786

88-
let params = &Self::params(&parts.uri)?;
89-
let params: Vec<(&str, &str)> = params
90-
.iter()
91-
.map(|(k, v)| (k.as_str(), v.as_str()))
92-
.collect();
87+
// Preparing to remove the params field. We are leaving it in place for now
88+
// to avoid breaking the ABI, but no longer pass or accept values in it.
89+
// https://github.com/fermyon/spin/issues/663
90+
let params = vec![];
9391

9492
let body = Some(&bytes[..]);
9593
let uri = match parts.uri.path_and_query() {
@@ -187,15 +185,6 @@ impl SpinHttpExecutor {
187185

188186
Ok(())
189187
}
190-
191-
fn params(uri: &Uri) -> Result<Vec<(String, String)>> {
192-
match uri.query() {
193-
Some(q) => Ok(url::form_urlencoded::parse(q.as_bytes())
194-
.into_owned()
195-
.collect::<Vec<_>>()),
196-
None => Ok(vec![]),
197-
}
198-
}
199188
}
200189

201190
fn contextualise_err(e: anyhow::Error) -> anyhow::Error {

crates/http/tests/rust-http-test/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ struct SpinHttp {}
66

77
impl spin_http::SpinHttp for SpinHttp {
88
fn handle_http_request(req: Request) -> Response {
9-
assert!(req.params.contains(&("abc".to_string(), "def".to_string())));
9+
assert!(req.params.is_empty());
10+
assert!(req.uri.contains("?abc=def"));
1011

1112
assert!(req
1213
.headers

crates/outbound-http/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ impl wasi_outbound_http::WasiOutboundHttp for OutboundHttp {
7070
let headers = request_headers(req.headers)?;
7171
let body = req.body.unwrap_or_default().to_vec();
7272

73+
if !req.params.is_empty() {
74+
tracing::log::warn!("HTTP params field is deprecated");
75+
}
76+
7377
match Handle::try_current() {
7478
// If running in a Tokio runtime, spawn a new blocking executor
7579
// that will send the HTTP request, and block on its execution.

sdk/rust/src/outbound_http.rs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use http::{header::HeaderName, HeaderValue, Uri};
1+
use http::{header::HeaderName, HeaderValue};
22

33
use super::http::{Request, Response};
44

@@ -16,12 +16,9 @@ pub fn send_request(req: Request) -> Result<Response> {
1616

1717
let method = req.method.try_into()?;
1818

19-
let (uri, params) = split_uri(req.uri)?;
19+
let uri = req.uri.to_string();
2020

21-
let params = &params
22-
.iter()
23-
.map(|(k, v)| (k.as_str(), v.as_str()))
24-
.collect::<Vec<_>>();
21+
let params = vec![];
2522

2623
let headers = &req
2724
.headers
@@ -34,7 +31,7 @@ pub fn send_request(req: Request) -> Result<Response> {
3431
let out_req = OutboundRequest {
3532
method,
3633
uri: &uri,
37-
params,
34+
params: &params,
3835
headers,
3936
body,
4037
};
@@ -55,23 +52,6 @@ pub fn send_request(req: Request) -> Result<Response> {
5552
.map_err(|_| OutboundHttpError::RuntimeError)
5653
}
5754

58-
fn split_uri(uri: Uri) -> Result<(String, Vec<(String, String)>)> {
59-
let params = form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes())
60-
.into_owned()
61-
.collect();
62-
let uri_without_params = {
63-
let mut parts = uri.into_parts();
64-
if let Some(paq) = parts.path_and_query.as_mut() {
65-
// Rebuild PathAndQuery from just path
66-
*paq = paq.path().try_into().unwrap();
67-
}
68-
Uri::from_parts(parts)
69-
.map_err(|_| OutboundHttpError::InvalidUrl)?
70-
.to_string()
71-
};
72-
Ok((uri_without_params, params))
73-
}
74-
7555
fn try_header_to_strs<'k, 'v>(
7656
header: (&'k HeaderName, &'v HeaderValue),
7757
) -> Result<(&'k str, &'v str)> {

0 commit comments

Comments
 (0)