Skip to content

Commit

Permalink
Optional fields, and align with upstream pr
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottt committed Nov 7, 2023
1 parent f088227 commit aebbe78
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
.downcast::<ErrorCode>()
.expect("expected a wasi-http ErrorCode"),
ErrorCode::HttpRequestError(HttpRequestErrorPayload {
status_code: 405,
status_code: Some(405),
..
}),
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
.downcast::<ErrorCode>()
.expect("expected a wasi-http ErrorCode"),
ErrorCode::HttpRequestError(HttpRequestErrorPayload {
status_code: 400,
status_code: Some(400),
..
}),
));
Expand Down
8 changes: 4 additions & 4 deletions crates/wasi-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub mod bindings {

pub(crate) fn dns_error(rcode: String, info_code: u16) -> bindings::http::types::ErrorCode {
bindings::http::types::ErrorCode::DnsError(bindings::http::types::DnsErrorPayload {
rcode,
info_code,
rcode: Some(rcode),
info_code: Some(info_code),
})
}

Expand All @@ -50,8 +50,8 @@ pub(crate) fn http_request_error(
) -> bindings::http::types::ErrorCode {
bindings::http::types::ErrorCode::HttpRequestError(
bindings::http::types::HttpRequestErrorPayload {
status_code,
status_phrase,
status_code: Some(status_code),
status_phrase: Some(status_phrase),
},
)
}
52 changes: 26 additions & 26 deletions crates/wasi-http/wit/deps/http/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ interface types {
other(string)
}

// The cases of this variant correspond to the IANA HTTP Proxy Error Types:
// https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types
/// The cases of this variant correspond to the IANA HTTP Proxy Error Types:
/// https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types
variant error-code {
DNS-timeout,
DNS-error(DNS-error-payload),
Expand All @@ -48,13 +48,13 @@ interface types {
HTTP-request-error(HTTP-request-error-payload),
HTTP-request-denied,
HTTP-response-incomplete,
HTTP-response-header-section-size(u32),
HTTP-response-header-section-size(option<u32>),
HTTP-response-header-size(field-size-payload),
HTTP-response-body-size(u32),
HTTP-response-trailer-section-size(u32),
HTTP-response-body-size(option<u32>),
HTTP-response-trailer-section-size(option<u32>),
HTTP-response-trailer-size(field-size-payload),
HTTP-response-transfer-coding(string),
HTTP-response-content-coding(string),
HTTP-response-transfer-coding(option<string>),
HTTP-response-content-coding(option<string>),
HTTP-response-timeout,
HTTP-upgrade-failed,
HTTP-protocol-error,
Expand All @@ -64,35 +64,28 @@ interface types {
proxy-loop-detected
}

// Defines the case payload type for `DNS-error` above:
/// Defines the case payload type for `DNS-error` above:
record DNS-error-payload {
rcode: string,
info-code: u16
rcode: option<string>,
info-code: option<u16>
}

// Defines the case payload type for `TLS-alert-received` above:
/// Defines the case payload type for `TLS-alert-received` above:
record TLS-alert-received-payload {
alert-ID: u8,
alert-message: string
alert-ID: option<u8>,
alert-message: option<string>
}

// Defines the case payload type for `HTTP-request-error` above:
/// Defines the case payload type for `HTTP-request-error` above:
record HTTP-request-error-payload {
status-code: u16,
status-phrase: string
status-code: option<u16>,
status-phrase: option<string>
}

// Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
/// Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
record field-size-payload {
field-name: string,
field-size: u32
}

/// This tyep enumerates the different kinds of errors that may occur when
/// setting or appending to a `fields` resource.
variant header-error {
invalid-syntax,
forbidden,
field-name: option<string>,
field-size: option<u32>
}

/// Attempts to extract a http-related `error` from the stream `error`
Expand All @@ -107,6 +100,13 @@ interface types {
/// are http-related errors.
http-error: func(err: borrow<stream-error>) -> option<error-code>;

/// This tyep enumerates the different kinds of errors that may occur when
/// setting or appending to a `fields` resource.
variant header-error {
invalid-syntax,
forbidden,
}

/// Field keys are always strings.
type field-key = string;

Expand Down
52 changes: 26 additions & 26 deletions crates/wasi/wit/deps/http/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ interface types {
other(string)
}

// The cases of this variant correspond to the IANA HTTP Proxy Error Types:
// https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types
/// The cases of this variant correspond to the IANA HTTP Proxy Error Types:
/// https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types
variant error-code {
DNS-timeout,
DNS-error(DNS-error-payload),
Expand All @@ -48,13 +48,13 @@ interface types {
HTTP-request-error(HTTP-request-error-payload),
HTTP-request-denied,
HTTP-response-incomplete,
HTTP-response-header-section-size(u32),
HTTP-response-header-section-size(option<u32>),
HTTP-response-header-size(field-size-payload),
HTTP-response-body-size(u32),
HTTP-response-trailer-section-size(u32),
HTTP-response-body-size(option<u32>),
HTTP-response-trailer-section-size(option<u32>),
HTTP-response-trailer-size(field-size-payload),
HTTP-response-transfer-coding(string),
HTTP-response-content-coding(string),
HTTP-response-transfer-coding(option<string>),
HTTP-response-content-coding(option<string>),
HTTP-response-timeout,
HTTP-upgrade-failed,
HTTP-protocol-error,
Expand All @@ -64,35 +64,28 @@ interface types {
proxy-loop-detected
}

// Defines the case payload type for `DNS-error` above:
/// Defines the case payload type for `DNS-error` above:
record DNS-error-payload {
rcode: string,
info-code: u16
rcode: option<string>,
info-code: option<u16>
}

// Defines the case payload type for `TLS-alert-received` above:
/// Defines the case payload type for `TLS-alert-received` above:
record TLS-alert-received-payload {
alert-ID: u8,
alert-message: string
alert-ID: option<u8>,
alert-message: option<string>
}

// Defines the case payload type for `HTTP-request-error` above:
/// Defines the case payload type for `HTTP-request-error` above:
record HTTP-request-error-payload {
status-code: u16,
status-phrase: string
status-code: option<u16>,
status-phrase: option<string>
}

// Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
/// Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
record field-size-payload {
field-name: string,
field-size: u32
}

/// This tyep enumerates the different kinds of errors that may occur when
/// setting or appending to a `fields` resource.
variant header-error {
invalid-syntax,
forbidden,
field-name: option<string>,
field-size: option<u32>
}

/// Attempts to extract a http-related `error` from the stream `error`
Expand All @@ -107,6 +100,13 @@ interface types {
/// are http-related errors.
http-error: func(err: borrow<stream-error>) -> option<error-code>;

/// This tyep enumerates the different kinds of errors that may occur when
/// setting or appending to a `fields` resource.
variant header-error {
invalid-syntax,
forbidden,
}

/// Field keys are always strings.
type field-key = string;

Expand Down
8 changes: 4 additions & 4 deletions src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,15 @@ impl hyper::service::Service<Request> for ProxyHandler {
} else if err.is_parse_status() || err.is_user() {
http_types::ErrorCode::HttpRequestError(
http_types::HttpRequestErrorPayload {
status_code: 400,
status_phrase: "".to_string(),
status_code: Some(400),
status_phrase: Some("".to_string()),
},
)
} else if err.is_parse_too_large() {
http_types::ErrorCode::HttpRequestError(
http_types::HttpRequestErrorPayload {
status_code: 413,
status_phrase: "".to_string(),
status_code: Some(413),
status_phrase: Some("".to_string()),
},
)
} else {
Expand Down

0 comments on commit aebbe78

Please sign in to comment.