From b6453af53a6b5d17bc7b486e5372b885d77bda43 Mon Sep 17 00:00:00 2001 From: Toshit Chawda Date: Sat, 5 Oct 2024 09:35:10 -0700 Subject: [PATCH] send empty content-length --- Cargo.lock | 4 ++-- client/Cargo.toml | 2 +- client/package.json | 2 +- client/src/lib.rs | 25 +++++++++++++++++-------- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a939613..29c88b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -683,7 +683,7 @@ dependencies = [ [[package]] name = "epoxy-client" -version = "2.1.5" +version = "2.1.6" dependencies = [ "async-compression", "async-trait", diff --git a/client/Cargo.toml b/client/Cargo.toml index 29f7cc3..2b99d1c 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "epoxy-client" -version = "2.1.5" +version = "2.1.6" edition = "2021" [lib] diff --git a/client/package.json b/client/package.json index 1d6ebde..9a447cd 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "@mercuryworkshop/epoxy-tls", - "version": "2.1.5-1", + "version": "2.1.6-1", "description": "A wasm library for using raw encrypted tls/ssl/tcp/udp/https/websocket streams on the browser", "scripts": { "build": "./build.sh" diff --git a/client/src/lib.rs b/client/src/lib.rs index 67eaa23..6411fda 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -9,7 +9,10 @@ use cfg_if::cfg_if; use futures_util::future::Either; use futures_util::TryStreamExt; use http::{ - header::{InvalidHeaderName, InvalidHeaderValue}, + header::{ + InvalidHeaderName, InvalidHeaderValue, ACCEPT_ENCODING, CONNECTION, CONTENT_LENGTH, + CONTENT_TYPE, HOST, USER_AGENT, + }, method::InvalidMethod, uri::{InvalidUri, InvalidUriParts}, HeaderName, HeaderValue, Method, Request, Response, @@ -573,7 +576,9 @@ impl EpoxyClient { } }); - let mut request_builder = Request::builder().uri(url.clone()).method(request_method); + let mut request_builder = Request::builder() + .uri(url.clone()) + .method(request_method.clone()); // Generic InvalidRequest because this only returns None if the builder has some error // which we don't know @@ -583,20 +588,20 @@ impl EpoxyClient { cfg_if! { if #[cfg(feature = "full")] { - headers_map.insert("Accept-Encoding", HeaderValue::from_static("gzip, br")); + headers_map.insert(ACCEPT_ENCODING, HeaderValue::from_static("gzip, br")); } else { - headers_map.insert("Accept-Encoding", HeaderValue::from_static("identity")); + headers_map.insert(ACCEPT_ENCODING, HeaderValue::from_static("identity")); } } - headers_map.insert("Connection", HeaderValue::from_static("keep-alive")); - headers_map.insert("User-Agent", HeaderValue::from_str(&self.user_agent)?); + headers_map.insert(CONNECTION, HeaderValue::from_static("keep-alive")); + headers_map.insert(USER_AGENT, HeaderValue::from_str(&self.user_agent)?); headers_map.insert( - "Host", + HOST, HeaderValue::from_str(&format!("{}{}", host, port_str))?, ); if let Some(content_type) = body_content_type { - headers_map.insert("Content-Type", HeaderValue::from_str(&content_type)?); + headers_map.insert(CONTENT_TYPE, HeaderValue::from_str(&content_type)?); } if let Some(headers) = headers { @@ -608,6 +613,10 @@ impl EpoxyClient { } } + if matches!(request_method, Method::POST | Method::PUT | Method::PATCH) && body.is_empty() { + headers_map.insert(CONTENT_LENGTH, 0.into()); + } + let (mut response, response_uri, redirected) = self .send_req(request_builder.body(HttpBody::new(body))?, request_redirect) .await?;