From b942bcc4a62f98b21f51536664bd52a251d81327 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 22 Mar 2018 07:44:16 -0700 Subject: [PATCH] Fix long client urls #129 --- CHANGES.md | 2 ++ src/client/writer.rs | 30 +++++++++++++++--------------- src/server/shared.rs | 12 +++++++++++- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index dd92b1408..b45ec2725 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,8 @@ ## 0.4.11 +* Fix long client urls #129 + * Fix client connection pooling * Use more ergonomic `actix_web::Error` instead of `http::Error` for `HttpResponseBuilder::body()` diff --git a/src/client/writer.rs b/src/client/writer.rs index be60c1c0a..cd50359ce 100644 --- a/src/client/writer.rs +++ b/src/client/writer.rs @@ -98,26 +98,26 @@ impl HttpClientWriter { self.flags.insert(Flags::STARTED); self.encoder = content_encoder(self.buffer.clone(), msg); + if msg.upgrade() { + self.flags.insert(Flags::UPGRADE); + } + // render message { - let mut buffer = self.buffer.get_mut(); - if let Body::Binary(ref bytes) = *msg.body() { - buffer.reserve(256 + msg.headers().len() * AVERAGE_HEADER_SIZE + bytes.len()); - } else { - buffer.reserve(256 + msg.headers().len() * AVERAGE_HEADER_SIZE); - } - - if msg.upgrade() { - self.flags.insert(Flags::UPGRADE); - } - // status line - let _ = write!(buffer, "{} {} {:?}\r\n", - msg.method(), - msg.uri().path_and_query().map(|u| u.as_str()).unwrap_or("/"), - msg.version()); + write!(self.buffer, "{} {} {:?}\r\n", + msg.method(), + msg.uri().path_and_query().map(|u| u.as_str()).unwrap_or("/"), + msg.version())?; // write headers + let mut buffer = self.buffer.get_mut(); + if let Body::Binary(ref bytes) = *msg.body() { + buffer.reserve(msg.headers().len() * AVERAGE_HEADER_SIZE + bytes.len()); + } else { + buffer.reserve(msg.headers().len() * AVERAGE_HEADER_SIZE); + } + for (key, value) in msg.headers() { let v = value.as_ref(); let k = key.as_str().as_bytes(); diff --git a/src/server/shared.rs b/src/server/shared.rs index ed87ca07c..bb3269c05 100644 --- a/src/server/shared.rs +++ b/src/server/shared.rs @@ -1,4 +1,4 @@ -use std::mem; +use std::{io, mem}; use std::cell::RefCell; use std::rc::Rc; use std::collections::VecDeque; @@ -138,3 +138,13 @@ impl Clone for SharedBytes { SharedBytes(self.0.clone(), self.1.clone()) } } + +impl io::Write for SharedBytes { + fn write(&mut self, buf: &[u8]) -> io::Result { + self.extend_from_slice(buf); + Ok(buf.len()) + } + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +}