Rename test function as_write_vec -> into_written_bytes
Tests use `Response::as_write_vec` to inspect the outgoing HTTP/1.1 request line and headers. The current version has two problems: 1. Called `as_write_vec` when it actually returns a `&[u8]`. 2. Inspects/uses the `Response::stream` without consuming `Response`. The first problem is trivial, but the second is subtle. Currently all calls on `Response` that works with the internal `Response::stream` consumes `self` (`into_string`, `into_reader`). `Response` is by itself `Send + Sync`, and must be so because the nested Stream is `Read + Write + Send + Sync`. However for implementors of `TLSStream`, it would be nice to relax the `Sync` requirement. Assumption: If all fields in Response are `Sync` except `Response::stream`, but any access to `stream` consumes `Response`, we can consider the entire `Response` `Sync`. This assumption can help us relax the `TlsStream` `Sync` requirement in a later PR.
This commit is contained in:
@@ -120,7 +120,7 @@ fn escape_path() {
|
||||
test::make_response(200, "OK", vec![], vec![])
|
||||
});
|
||||
let resp = get("test://host/escape_path here").call().unwrap();
|
||||
let vec = resp.as_write_vec();
|
||||
let vec = resp.into_written_bytes();
|
||||
let s = String::from_utf8_lossy(&vec);
|
||||
assert!(s.contains("GET /escape_path%20here HTTP/1.1"))
|
||||
}
|
||||
@@ -198,7 +198,7 @@ pub fn host_no_port() {
|
||||
test::make_response(200, "OK", vec![], vec![])
|
||||
});
|
||||
let resp = get("test://myhost/host_no_port").call().unwrap();
|
||||
let vec = resp.as_write_vec();
|
||||
let vec = resp.into_written_bytes();
|
||||
let s = String::from_utf8_lossy(&vec);
|
||||
assert!(s.contains("\r\nHost: myhost\r\n"));
|
||||
}
|
||||
@@ -209,7 +209,7 @@ pub fn host_with_port() {
|
||||
test::make_response(200, "OK", vec![], vec![])
|
||||
});
|
||||
let resp = get("test://myhost:234/host_with_port").call().unwrap();
|
||||
let vec = resp.as_write_vec();
|
||||
let vec = resp.into_written_bytes();
|
||||
let s = String::from_utf8_lossy(&vec);
|
||||
assert!(s.contains("\r\nHost: myhost:234\r\n"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user