Skip to content

Commit

Permalink
Merge pull request #5 from purduehackers/request-fix
Browse files Browse the repository at this point in the history
Fix requests
  • Loading branch information
ImTheSquid authored Dec 6, 2024
2 parents 27e52c9 + d0f94b3 commit d7e8ca6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sign-firmware"
version = "0.1.5"
version = "0.1.6"
authors = ["Jack Hogan <jackhogan11@gmail.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down
16 changes: 12 additions & 4 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub async fn generate_tls(url: &str) -> anyhow::Result<EspAsyncTls<EspTlsSocket>
Ok(tls)
}

pub fn create_raw_request<T>(request: http::Request<T>) -> String {
pub fn create_raw_request_no_body<T>(request: &http::Request<T>) -> String {
let method = request.method();
let uri = request.uri();
let headers = request.headers();
Expand All @@ -61,6 +61,14 @@ pub fn create_raw_request<T>(request: http::Request<T>) -> String {
request_text
}

pub fn create_raw_request<T: ToString>(request: &http::Request<T>) -> String {
let mut text = create_raw_request_no_body(request);

text.push_str(&request.body().to_string());

text
}

pub async fn handle_redirect(url: &str) -> anyhow::Result<EspAsyncTls<EspTlsSocket>> {
let request = Request::builder()
.method("GET")
Expand All @@ -72,7 +80,7 @@ pub async fn handle_redirect(url: &str) -> anyhow::Result<EspAsyncTls<EspTlsSock

let mut tls = generate_tls(url).await?;

let request_text = create_raw_request(request);
let request_text = create_raw_request_no_body(&request);

tls.write_all(request_text.as_bytes())
.await
Expand Down Expand Up @@ -102,7 +110,7 @@ pub async fn handle_redirect(url: &str) -> anyhow::Result<EspAsyncTls<EspTlsSock
.unwrap();

let tls = generate_tls(location).await?;
let request_text = create_raw_request(request);
let request_text = create_raw_request_no_body(&request);

tls.write_all(request_text.as_bytes())
.await
Expand Down Expand Up @@ -131,7 +139,7 @@ pub async fn self_update(leds: &mut Leds) -> anyhow::Result<()> {

let mut tls = generate_tls(url).await?;

let request_text = create_raw_request(request);
let request_text = create_raw_request_no_body(&request);

tls.write_all(request_text.as_bytes())
.await
Expand Down
2 changes: 1 addition & 1 deletion src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub async fn post_event(event: PrinterEvent) -> anyhow::Result<()> {
.body(serde_json::to_string(&event.message())?)
.unwrap();

let request_text = create_raw_request(request);
let request_text = create_raw_request(&request);

tls.write_all(request_text.as_bytes())
.await
Expand Down

0 comments on commit d7e8ca6

Please sign in to comment.