Skip to content

Commit

Permalink
http: allocate dynamically the space for HTTP response
Browse files Browse the repository at this point in the history
  • Loading branch information
hch12907 committed Nov 19, 2023
1 parent c62d5f9 commit ea41e82
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/http/curl_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Request {
// UNWRAP-SAFETY: HTTP is supported.
self.curl.http_headers(self.header_list).unwrap();

let mut response = Vec::with_capacity(8192);
let mut response = Vec::with_capacity(1024);
let mut transfer = self.curl.transfer();

transfer
Expand Down
6 changes: 3 additions & 3 deletions src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ impl Response {
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
}

pub fn into_string(mut self) -> Result<String, io::Error> {
let mut vec = vec![0; 1024 * 1024];
let read = self.reader.read(&mut vec)?;
pub fn into_string(self) -> Result<String, io::Error> {
let mut vec = vec![0; 1024];
let read = self.reader.take(2 * 1024 * 1024).read(&mut vec)?;
vec.resize(read, 0);
String::from_utf8(vec).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
}
Expand Down

0 comments on commit ea41e82

Please sign in to comment.