fingers

Finger client library in Rust
Log | Files | Refs | README | LICENSE

commit f138f6c16a7764a53b1c2cd111130b5dd835e28a
parent 24834f39517ac9a2c3e16cc1c981b1cdbdbf11d8
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Wed,  1 Dec 2021 22:28:48 -0800

Add max response len

Diffstat:
Msrc/lib.rs | 9++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs @@ -34,7 +34,7 @@ pub struct Request { query: String, host: String, timeout: Option<u64>, // seconds - // max_response_len: Option<u64>, + max_response_len: Option<u64>, } /// From the draft spec: @@ -64,7 +64,7 @@ pub fn finger(query: &str, host: &str) -> Request { query: q.to_owned(), host: host.to_owned(), timeout: Some(10), - // max_response_len: Some(1024 * 10), // 10KB + max_response_len: Some(1024 * 10), // 10KB } } impl Request { @@ -92,7 +92,10 @@ impl Request { stream.set_read_timeout(Some((start + timeout) - Instant::now()))?; let mut line: Vec<u8> = vec![]; - stream.read_to_end(&mut line)?; + match self.max_response_len { + Some(mrl) => stream.take(mrl).read_to_end(&mut line)?, + None => stream.read_to_end(&mut line)?, + }; return Ok(str::from_utf8(&line)?.to_owned()); }