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

Include origin path when preparing request #1562

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions tonic/src/client/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
};
use http::{
header::{HeaderValue, CONTENT_TYPE, TE},
uri::{Parts, PathAndQuery, Uri},
uri::{PathAndQuery, Uri},
};
use http_body::Body;
use std::{fmt, future};
Expand Down Expand Up @@ -372,13 +372,20 @@ impl GrpcConfig {
request: Request<BoxBody>,
path: PathAndQuery,
) -> http::Request<BoxBody> {
let scheme = self.origin.scheme().cloned();
let authority = self.origin.authority().cloned();

let mut parts = Parts::default();
parts.path_and_query = Some(path);
parts.scheme = scheme;
parts.authority = authority;
let mut parts = self.origin.clone().into_parts();

match &parts.path_and_query {
Some(pnq) if pnq != "/" => {
parts.path_and_query = Some(
format!("{}{}", pnq.path(), path)
.parse()
.expect("must form valid path_and_query"),
)
}
_ => {
parts.path_and_query = Some(path);
}
}

let uri = Uri::from_parts(parts).expect("path_and_query only is valid Uri");

Expand Down