Use correct host on redirect. (#180)

This commit is contained in:
Jacob Hoffman-Andrews
2020-10-06 00:10:56 -07:00
committed by GitHub
parent 2d4b42e298
commit 5b75deccef
2 changed files with 30 additions and 1 deletions

View File

@@ -1,3 +1,9 @@
use std::{
io::{self, Write},
net::TcpStream,
};
use test::testserver::{self, TestServer};
use crate::test;
use super::super::*;
@@ -76,6 +82,25 @@ fn redirect_get() {
assert_eq!(resp.header("x-foo").unwrap(), "bar");
}
#[test]
fn redirect_host() {
// Set up a redirect to a host that doesn't exist; it should fail.
let srv = TestServer::new(|mut stream: TcpStream| -> io::Result<()> {
testserver::read_headers(&stream);
write!(stream, "HTTP/1.1 302 Found\r\n")?;
write!(stream, "Location: http://example.invalid/\r\n")?;
write!(stream, "\r\n")?;
Ok(())
});
let url = format!("http://localhost:{}/", srv.port);
let resp = crate::get(&url).call();
assert!(
matches!(resp.synthetic_error(), Some(Error::DnsFailed(_))),
"{:?}",
resp.synthetic_error()
);
}
#[test]
fn redirect_post() {
test::set_handler("/redirect_post1", |_| {