Skip to content

Commit 7af92d0

Browse files
committed
Update for upstream changes to the error-code variant
1 parent 0e56721 commit 7af92d0

File tree

7 files changed

+30
-70
lines changed

7 files changed

+30
-70
lines changed

crates/test-programs/src/bin/http_outbound_request_unknown_method.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use test_programs::wasi::http::types::{ErrorCode, HttpRequestErrorPayload, Method, Scheme};
1+
use test_programs::wasi::http::types::{ErrorCode, Method, Scheme};
22

33
fn main() {
44
let res = test_programs::http::request(
@@ -14,9 +14,6 @@ fn main() {
1414
res.unwrap_err()
1515
.downcast::<ErrorCode>()
1616
.expect("expected a wasi-http ErrorCode"),
17-
ErrorCode::HttpRequestError(HttpRequestErrorPayload {
18-
status_code: Some(405),
19-
..
20-
}),
17+
ErrorCode::HttpProtocolError,
2118
));
2219
}

crates/test-programs/src/bin/http_outbound_request_unsupported_scheme.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use test_programs::wasi::http::types::{ErrorCode, HttpRequestErrorPayload, Method, Scheme};
1+
use test_programs::wasi::http::types::{ErrorCode, Method, Scheme};
22

33
fn main() {
44
let res = test_programs::http::request(
@@ -14,9 +14,6 @@ fn main() {
1414
res.unwrap_err()
1515
.downcast::<ErrorCode>()
1616
.expect("expected a wasi-http ErrorCode"),
17-
ErrorCode::HttpRequestError(HttpRequestErrorPayload {
18-
status_code: Some(400),
19-
..
20-
}),
17+
ErrorCode::HttpProtocolError,
2118
));
2219
}

crates/wasi-http/src/http_impl.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{
33
outgoing_handler,
44
types::{self, Scheme},
55
},
6-
http_request_error,
76
types::{HostFutureIncomingResponse, HostOutgoingRequest, OutgoingRequest},
87
WasiHttpView,
98
};
@@ -35,32 +34,27 @@ impl<T: WasiHttpView> outgoing_handler::Host for T {
3534
let req = self.table().delete(request_id)?;
3635

3736
let method = match req.method {
38-
crate::bindings::http::types::Method::Get => Method::GET,
39-
crate::bindings::http::types::Method::Head => Method::HEAD,
40-
crate::bindings::http::types::Method::Post => Method::POST,
41-
crate::bindings::http::types::Method::Put => Method::PUT,
42-
crate::bindings::http::types::Method::Delete => Method::DELETE,
43-
crate::bindings::http::types::Method::Connect => Method::CONNECT,
44-
crate::bindings::http::types::Method::Options => Method::OPTIONS,
45-
crate::bindings::http::types::Method::Trace => Method::TRACE,
46-
crate::bindings::http::types::Method::Patch => Method::PATCH,
47-
crate::bindings::http::types::Method::Other(method) => {
48-
return Ok(Err(http_request_error(
49-
405,
50-
format!("unknown method {method}"),
51-
)));
37+
types::Method::Get => Method::GET,
38+
types::Method::Head => Method::HEAD,
39+
types::Method::Post => Method::POST,
40+
types::Method::Put => Method::PUT,
41+
types::Method::Delete => Method::DELETE,
42+
types::Method::Connect => Method::CONNECT,
43+
types::Method::Options => Method::OPTIONS,
44+
types::Method::Trace => Method::TRACE,
45+
types::Method::Patch => Method::PATCH,
46+
types::Method::Other(_) => {
47+
// We can't support arbitrary methods
48+
return Ok(Err(types::ErrorCode::HttpProtocolError));
5249
}
5350
};
5451

5552
let (use_tls, scheme, port) = match req.scheme.unwrap_or(Scheme::Https) {
5653
Scheme::Http => (false, "http://", 80),
5754
Scheme::Https => (true, "https://", 443),
58-
Scheme::Other(scheme) => {
59-
return Ok(Err(http_request_error(
60-
400,
61-
format!("unsupported scheme {scheme}"),
62-
)))
63-
}
55+
56+
// We can only support http/https
57+
Scheme::Other(_) => return Ok(Err(types::ErrorCode::HttpProtocolError)),
6458
};
6559

6660
let authority = if let Some(authority) = req.authority {

crates/wasi-http/src/lib.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,3 @@ pub(crate) fn dns_error(rcode: String, info_code: u16) -> bindings::http::types:
4343
info_code: Some(info_code),
4444
})
4545
}
46-
47-
pub(crate) fn http_request_error(
48-
status_code: u16,
49-
status_phrase: String,
50-
) -> bindings::http::types::ErrorCode {
51-
bindings::http::types::ErrorCode::HttpRequestError(
52-
bindings::http::types::HttpRequestErrorPayload {
53-
status_code: Some(status_code),
54-
status_phrase: Some(status_phrase),
55-
},
56-
)
57-
}

crates/wasi-http/wit/deps/http/types.wit

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ interface types {
4545
TLS-protocol-error,
4646
TLS-certificate-error,
4747
TLS-alert-received(TLS-alert-received-payload),
48-
HTTP-request-error(HTTP-request-error-payload),
4948
HTTP-request-denied,
49+
HTTP-request-length-required,
50+
HTTP-request-content-too-large,
51+
HTTP-request-URI-too-long,
52+
HTTP-request-header-section-size(option<u32>),
53+
HTTP-request-header-size(option<field-size-payload>),
5054
HTTP-response-incomplete,
5155
HTTP-response-header-section-size(option<u32>),
5256
HTTP-response-header-size(field-size-payload),
@@ -76,12 +80,6 @@ interface types {
7680
alert-message: option<string>
7781
}
7882

79-
/// Defines the case payload type for `HTTP-request-error` above:
80-
record HTTP-request-error-payload {
81-
status-code: option<u16>,
82-
status-phrase: option<string>
83-
}
84-
8583
/// Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
8684
record field-size-payload {
8785
field-name: option<string>,

crates/wasi/wit/deps/http/types.wit

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ interface types {
4545
TLS-protocol-error,
4646
TLS-certificate-error,
4747
TLS-alert-received(TLS-alert-received-payload),
48-
HTTP-request-error(HTTP-request-error-payload),
4948
HTTP-request-denied,
49+
HTTP-request-length-required,
50+
HTTP-request-content-too-large,
51+
HTTP-request-URI-too-long,
52+
HTTP-request-header-section-size(option<u32>),
53+
HTTP-request-header-size(option<field-size-payload>),
5054
HTTP-response-incomplete,
5155
HTTP-response-header-section-size(option<u32>),
5256
HTTP-response-header-size(field-size-payload),
@@ -76,12 +80,6 @@ interface types {
7680
alert-message: option<string>
7781
}
7882

79-
/// Defines the case payload type for `HTTP-request-error` above:
80-
record HTTP-request-error-payload {
81-
status-code: option<u16>,
82-
status-phrase: option<string>
83-
}
84-
8583
/// Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
8684
record field-size-payload {
8785
field-name: option<string>,

src/commands/serve.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -369,20 +369,8 @@ impl hyper::service::Service<Request> for ProxyHandler {
369369
body.map_err(|err| {
370370
if err.is_timeout() {
371371
http_types::ErrorCode::HttpResponseTimeout
372-
} else if err.is_parse_status() || err.is_user() {
373-
http_types::ErrorCode::HttpRequestError(
374-
http_types::HttpRequestErrorPayload {
375-
status_code: Some(400),
376-
status_phrase: Some("".to_string()),
377-
},
378-
)
379372
} else if err.is_parse_too_large() {
380-
http_types::ErrorCode::HttpRequestError(
381-
http_types::HttpRequestErrorPayload {
382-
status_code: Some(413),
383-
status_phrase: Some("".to_string()),
384-
},
385-
)
373+
http_types::ErrorCode::HttpRequestContentTooLarge
386374
} else {
387375
http_types::ErrorCode::HttpProtocolError
388376
}

0 commit comments

Comments
 (0)