Skip to content

Commit

Permalink
add enabled argument to api
Browse files Browse the repository at this point in the history
  • Loading branch information
goatgoose committed Dec 16, 2024
1 parent 00f3218 commit 3f13019
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 11 additions & 2 deletions bindings/rust/s2n-tls-hyper/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ pub struct Builder<Http, ConnBuilder> {

impl<Http, ConnBuilder> Builder<Http, ConnBuilder> {
/// Allows communication with insecure HTTP endpoints in addition to secure HTTPS endpoints.
pub fn with_insecure_http(&mut self) -> &mut Self {
self.insecure_http = true;
pub fn with_insecure_http(&mut self, enabled: bool) -> &mut Self {
self.insecure_http = enabled;
self
}

Expand Down Expand Up @@ -274,4 +274,13 @@ mod tests {

Ok(())
}

#[tokio::test]
async fn default_builder() -> Result<(), Box<dyn StdError>> {
// Ensure that insecure HTTP is disabled by default.
let connector = HttpsConnector::builder(Config::default()).build();
assert!(!connector.insecure_http);

Ok(())
}
}
6 changes: 2 additions & 4 deletions bindings/rust/s2n-tls-hyper/tests/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,7 @@ async fn insecure_http() -> Result<(), Box<dyn Error + Send + Sync>> {
let connector = {
let config = common::config()?.build()?;
let mut builder = HttpsConnector::builder(config);
if enable_insecure_http {
builder.with_insecure_http();
}
builder.with_insecure_http(enable_insecure_http);
builder.build()
};

Expand All @@ -376,7 +374,7 @@ async fn insecure_http() -> Result<(), Box<dyn Error + Send + Sync>> {
let response = response.unwrap();
assert_eq!(response.status(), 200);
} else {
// By default, insecure HTTP is disabled, and the request should error.
// If insecure HTTP is disabled, the request should error.
let error = response.unwrap_err();

// Ensure an InvalidScheme error is produced.
Expand Down

0 comments on commit 3f13019

Please sign in to comment.