Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transport): Endpoint returns transport error #920

Merged
merged 1 commit into from Feb 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 7 additions & 10 deletions tonic/src/transport/channel/endpoint.rs
Expand Up @@ -6,10 +6,7 @@ use super::ClientTlsConfig;
use crate::transport::service::TlsConnector;
use crate::transport::Error;
use bytes::Bytes;
use http::{
uri::{InvalidUri, Uri},
HeaderValue,
};
use http::{uri::Uri, HeaderValue};
use std::{
convert::{TryFrom, TryInto},
fmt,
Expand Down Expand Up @@ -76,8 +73,8 @@ impl Endpoint {
/// # use tonic::transport::Endpoint;
/// Endpoint::from_shared("https://example.com".to_string());
/// ```
pub fn from_shared(s: impl Into<Bytes>) -> Result<Self, InvalidUri> {
let uri = Uri::from_maybe_shared(s.into())?;
pub fn from_shared(s: impl Into<Bytes>) -> Result<Self, Error> {
let uri = Uri::from_maybe_shared(s.into()).map_err(|e| Error::new_invalid_uri().with(e))?;
Ok(Self::from(uri))
}

Expand Down Expand Up @@ -404,23 +401,23 @@ impl From<Uri> for Endpoint {
}

impl TryFrom<Bytes> for Endpoint {
type Error = InvalidUri;
type Error = Error;

fn try_from(t: Bytes) -> Result<Self, Self::Error> {
Self::from_shared(t)
}
}

impl TryFrom<String> for Endpoint {
type Error = InvalidUri;
type Error = Error;

fn try_from(t: String) -> Result<Self, Self::Error> {
Self::from_shared(t.into_bytes())
}
}

impl TryFrom<&'static str> for Endpoint {
type Error = InvalidUri;
type Error = Error;

fn try_from(t: &'static str) -> Result<Self, Self::Error> {
Self::from_shared(t.as_bytes())
Expand All @@ -434,7 +431,7 @@ impl fmt::Debug for Endpoint {
}

impl FromStr for Endpoint {
type Err = InvalidUri;
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::try_from(s.to_string())
Expand Down