Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/http/HTTPThread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down
16 changes: 3 additions & 13 deletions src/http/InternalState.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,9 @@
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<HTTPResponseMetadata> drops on assignment; allocator param removed)
self.cloned_metadata = None;

// if exists we own this info
// (Option<CertificateInfo> 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).

Check warning on line 180 in src/http/InternalState.rs

View check run for this annotation

Claude / Claude Code Review

Incomplete same-class cleanup in InternalState::reset

The new comment says "Only `original_request_body` needs an explicit `deinit()`" — but two lines up, `self.compressed_body = MutableString::init_empty()` and `self.response_message_buffer = MutableString::init_empty()` (InternalState.rs:171-172) are the identical redundancy pattern this PR removes for `cloned_metadata`/`certificate_info`: the subsequent `*self = InternalState { compressed_body: MutableString::init_empty(), response_message_buffer: MutableString::init_empty(), ... }` drops-and-re
Comment thread
claude[bot] marked this conversation as resolved.
Resolved
self.original_request_body.deinit();
*self = InternalState {
body_out_str: body_msg,
Expand Down
43 changes: 20 additions & 23 deletions src/http/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4641,29 +4641,26 @@ impl<'a> HTTPClient<'a> {
self.state.cloned_metadata = None;
}

let mut certificate_info: Option<CertificateInfo> = 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),
Expand Down
Loading