Skip to content

Commit 69368f4

Browse files
JeffLabonteseanmonstar
authored andcommitted
refactor(client): update from deprecated Uri::port to port_part (#1722)
1 parent 7fb6e3a commit 69368f4

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

Diff for: src/client/connect/http.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ where
234234
Some(s) => s,
235235
None => return invalid_url(InvalidUrl::MissingAuthority, &self.handle),
236236
};
237-
let port = match dst.uri.port() {
238-
Some(port) => port,
237+
let port = match dst.uri.port_part() {
238+
Some(port) => port.as_u16(),
239239
None => if dst.uri.scheme_part() == Some(&Scheme::HTTPS) { 443 } else { 80 },
240240
};
241241

Diff for: src/client/connect/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ impl Destination {
7979
/// Get the port, if specified.
8080
#[inline]
8181
pub fn port(&self) -> Option<u16> {
82-
self.uri.port()
82+
match self.uri.port_part() {
83+
Some(port) => Some(port.as_u16()),
84+
None => None
85+
}
8386
}
8487

8588
/// Update the scheme of this destination.
@@ -140,7 +143,7 @@ impl Destination {
140143
.map_err(::error::Parse::from)?
141144
} else {
142145
let auth = host.parse::<uri::Authority>().map_err(::error::Parse::from)?;
143-
if auth.port().is_some() {
146+
if auth.port_part().is_some() { // std::uri::Authority::Uri
144147
return Err(::error::Parse::Uri.into());
145148
}
146149
auth

Diff for: src/client/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,9 @@ where C: Connect + Sync + 'static,
212212
format!("{}://{}", scheme, auth)
213213
}
214214
(None, Some(auth)) if is_http_connect => {
215-
let scheme = match auth.port() {
216-
Some(443) => {
215+
let port = auth.port_part().unwrap();
216+
let scheme = match port.as_str() {
217+
"443" => {
217218
set_scheme(req.uri_mut(), Scheme::HTTPS);
218219
"https"
219220
},
@@ -278,7 +279,7 @@ where C: Connect + Sync + 'static,
278279
.expect("HOST is always valid header name")
279280
.or_insert_with(|| {
280281
let hostname = uri.host().expect("authority implies host");
281-
if let Some(port) = uri.port() {
282+
if let Some(port) = uri.port_part() {
282283
let s = format!("{}:{}", hostname, port);
283284
HeaderValue::from_str(&s)
284285
} else {

0 commit comments

Comments
 (0)