support grpc (force http2 when grpc)
This commit is contained in:
parent
e39b8ac3c5
commit
461ef67ef2
2 changed files with 15 additions and 1 deletions
|
|
@ -226,7 +226,9 @@ where
|
||||||
let connector = builder.https_or_http().enable_all_versions().wrap_connector(http.clone());
|
let connector = builder.https_or_http().enable_all_versions().wrap_connector(http.clone());
|
||||||
let connector_h2 = builder_h2.https_or_http().enable_http2().wrap_connector(http);
|
let connector_h2 = builder_h2.https_or_http().enable_http2().wrap_connector(http);
|
||||||
let inner = Client::builder(LocalExecutor::new(_globals.runtime_handle.clone())).build::<_, B1>(connector);
|
let inner = Client::builder(LocalExecutor::new(_globals.runtime_handle.clone())).build::<_, B1>(connector);
|
||||||
let inner_h2 = Client::builder(LocalExecutor::new(_globals.runtime_handle.clone())).build::<_, B1>(connector_h2);
|
let inner_h2 = Client::builder(LocalExecutor::new(_globals.runtime_handle.clone()))
|
||||||
|
.http2_only(true)
|
||||||
|
.build::<_, B1>(connector_h2);
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
inner,
|
inner,
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,18 @@ pub(super) fn update_request_line<B>(
|
||||||
upstream_chosen: &Upstream,
|
upstream_chosen: &Upstream,
|
||||||
upstream_candidates: &UpstreamCandidates,
|
upstream_candidates: &UpstreamCandidates,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
// If request is grpc, HTTP/2 is required
|
||||||
|
if req
|
||||||
|
.headers()
|
||||||
|
.get(header::CONTENT_TYPE)
|
||||||
|
.map(|v| v.as_bytes().starts_with(b"application/grpc"))
|
||||||
|
== Some(true)
|
||||||
|
{
|
||||||
|
debug!("Must be http/2 for gRPC request.");
|
||||||
|
*req.version_mut() = Version::HTTP_2;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
// If not specified (force_httpXX_upstream) and https, version is preserved except for http/3
|
// If not specified (force_httpXX_upstream) and https, version is preserved except for http/3
|
||||||
if upstream_chosen.uri.scheme() == Some(&Scheme::HTTP) {
|
if upstream_chosen.uri.scheme() == Some(&Scheme::HTTP) {
|
||||||
// Change version to http/1.1 when destination scheme is http
|
// Change version to http/1.1 when destination scheme is http
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue