Add scheme to PoolKey and let port be None. (#84)
PoolKey calls unwrap() on an option that can be None. Specifically, the local variable `port` can be None when PoolKey is constructed with a Url whose scheme is unrecognized in url.port_or_known_default(). To fix that, make port an Option. Also, make scheme part of the PoolKey. This prevents, for instance, a stream opened for `https://example.com:9999` being reused on a request for `http://example.com:9999`. Remove the test-only pool.get() accessor. This was used in only one test, agent_pool in range.rs. This seemed like it was testing the agent more than it was testing ranges, so I moved it to agent.rs and edited to remove the range-testing parts. Also, reject unrecognized URLs earlier in connect_socket so they don't reach try_get_connection.
This commit is contained in:
committed by
GitHub
parent
00461fb5bd
commit
3014f58a28
@@ -291,6 +291,10 @@ pub(crate) fn combine_query(url: &Url, query: &QString, mix_queries: bool) -> St
|
||||
|
||||
/// Connect the socket, either by using the pool or grab a new one.
|
||||
fn connect_socket(unit: &Unit, use_pooled: bool) -> Result<(Stream, bool), Error> {
|
||||
match unit.url.scheme() {
|
||||
"http" | "https" | "test" => (),
|
||||
_ => return Err(Error::UnknownScheme(unit.url.scheme().to_string())),
|
||||
};
|
||||
if use_pooled {
|
||||
let state = &mut unit.agent.lock().unwrap();
|
||||
if let Some(agent) = state.as_mut() {
|
||||
|
||||
Reference in New Issue
Block a user