change Host header to have hostname and port

This commit is contained in:
Sean McArthur
2014-10-22 18:27:59 -07:00
parent 224cc709c3
commit 19045a2376
4 changed files with 76 additions and 35 deletions

View File

@@ -58,8 +58,12 @@ impl Request<Fresh> {
let stream: S = try_io!(NetworkStream::connect(host.as_slice(), port, url.scheme.as_slice()));
let stream = ThroughWriter(BufferedWriter::new(stream.dynamic()));
let mut headers = Headers::new();
headers.set(Host(format!("{}:{}", host, port)));
headers.set(Host {
hostname: host,
port: Some(port),
});
Ok(Request {
method: method,
@@ -188,32 +192,3 @@ impl Writer for Request<Streaming> {
}
}
#[cfg(test)]
mod tests {
use header::common::Host;
use method::Get;
use net::MockStream;
use url::Url;
use super::Request;
#[test]
fn test_host_header() {
fn check_host(url: &str, host_header: &str) {
let request = Request::with_stream::<MockStream>(
Get,
Url::parse(url).unwrap(),
).unwrap();
assert_eq!(
&Host(host_header.to_string()),
request.headers().get::<Host>().unwrap()
);
}
check_host("http://www.example.com/path", "www.example.com:80");
check_host("https://www.example.com/path", "www.example.com:443");
check_host("http://www.example.com:8080/path", "www.example.com:8080");
}
}