diff --git a/src/http/HTTPThread.rs b/src/http/HTTPThread.rs index 11c6b782b80c..52dec28bf6f5 100644 --- a/src/http/HTTPThread.rs +++ b/src/http/HTTPThread.rs @@ -249,9 +249,7 @@ impl RequestBodyBuffer { // A `Vec` cannot adopt a foreign allocator+buffer, so this // allocates a fresh Vec of the same capacity. // Callers that can should write into allocated_slice() directly instead. - let mut arraylist = Vec::with_capacity(self.allocated_slice().len()); - arraylist.clear(); - arraylist + Vec::with_capacity(self.allocated_slice().len()) } } diff --git a/src/http/InternalState.rs b/src/http/InternalState.rs index ece9e994eb63..96e6aee2fce4 100644 --- a/src/http/InternalState.rs +++ b/src/http/InternalState.rs @@ -167,27 +167,13 @@ impl<'a> InternalState<'a> { } pub fn reset(&mut self) { - // allocator param dropped (global mimalloc). - self.compressed_body = MutableString::init_empty(); - self.response_message_buffer = MutableString::init_empty(); - let body_msg = self.body_out_str; if let Some(body) = body_msg { crate::body_out::as_mut(body).reset(); } - // The boxed - // Zlib/Brotli/Zstd readers all impl Drop calling end()/destroy_instance - // (see the note in Decompressor.rs), so the `*self = ...` assignment below - // frees the FFI handle via drop glue — no explicit reset needed. - - // just in case we check and free to avoid leaks - // (Option drops on assignment; allocator param removed) - self.cloned_metadata = None; - - // if exists we own this info - // (Option drops on assignment; allocator param removed) - self.certificate_info = None; - + // `*self = ...` below drops every field via drop glue. Only + // `original_request_body` needs an explicit `deinit()` because + // `HTTPRequestBody` deliberately has no `Drop` (see HTTPRequestBody.rs). self.original_request_body.deinit(); *self = InternalState { body_out_str: body_msg, diff --git a/src/http/lib.rs b/src/http/lib.rs index 80d0b5aef39d..4f76341742fb 100644 --- a/src/http/lib.rs +++ b/src/http/lib.rs @@ -4641,29 +4641,26 @@ impl<'a> HTTPClient<'a> { self.state.cloned_metadata = None; } - let mut certificate_info: Option = None; - if let Some(info) = self.state.certificate_info.take() { - // transfer owner ship of the certificate info here - certificate_info = Some(info); - } else if let Some(metadata) = self.state.cloned_metadata.take() { - // transfer owner ship of the metadata here - return HTTPClientResult { - metadata: Some(metadata), - body: body_out::opt_mut(self.state.body_out_str), - redirected: self.flags.redirected, - fail: self.state.fail, - dns_error: self.state.dns_error, - dns_hostname: self.state.dns_hostname.take(), - // check if we are reporting cert errors, do not have a fail state and we are not done - has_more: certificate_info.is_some() - || (self.state.fail.is_none() && !self.state.is_done()), - body_size, - certificate_info: None, - can_stream: (self.state.request_stage == RequestStage::Body - || self.state.request_stage == RequestStage::ProxyBody) - && self.flags.is_streaming_request_body, - is_http2: self.flags.protocol != Protocol::Http1_1, - }; + let certificate_info = self.state.certificate_info.take(); + if certificate_info.is_none() { + if let Some(metadata) = self.state.cloned_metadata.take() { + // transfer ownership of the metadata here + return HTTPClientResult { + metadata: Some(metadata), + body: body_out::opt_mut(self.state.body_out_str), + redirected: self.flags.redirected, + fail: self.state.fail, + dns_error: self.state.dns_error, + dns_hostname: self.state.dns_hostname.take(), + has_more: self.state.fail.is_none() && !self.state.is_done(), + body_size, + certificate_info: None, + can_stream: (self.state.request_stage == RequestStage::Body + || self.state.request_stage == RequestStage::ProxyBody) + && self.flags.is_streaming_request_body, + is_http2: self.flags.protocol != Protocol::Http1_1, + }; + } } HTTPClientResult { body: body_out::opt_mut(self.state.body_out_str),