From 613eb4fe76714e4ec78cf45e8bb3301abcbb7bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=A3=E4=BA=AE?= Date: Wed, 24 Aug 2022 20:33:29 +0800 Subject: [PATCH] Do not require authority for UNIX domain sockets Copy from https://github.com/hyperium/h2/pull/487 Thanks for the help from Sascha Grunert. --- src/server.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/server.rs b/src/server.rs index 9f56f184a..19fcc15b0 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1465,14 +1465,20 @@ impl proto::Peer for Peer { // A request translated from HTTP/1 must not include the :authority // header if let Some(authority) = pseudo.authority { - let maybe_authority = uri::Authority::from_maybe_shared(authority.clone().into_inner()); - parts.authority = Some(maybe_authority.or_else(|why| { - malformed!( - "malformed headers: malformed authority ({:?}): {}", - authority, - why, - ) - })?); + // When connecting to a UNIX Domain Socket (UDS), then we might get a path for the + // authority field. If it's a local path and exists, then we do not error in that case + // and assume an UDS. + if !authority.is_empty() && !authority.ends_with(".sock") { + let maybe_authority = + uri::Authority::from_maybe_shared(authority.clone().into_inner()); + parts.authority = Some(maybe_authority.or_else(|why| { + malformed!( + "malformed headers: malformed authority ({:?}): {}", + authority, + why, + ) + })?); + } } // A :scheme is required, except CONNECT.