@@ -120,7 +120,7 @@ impl ProxyHandler {
120120 let never_ask_for_auth = self . config . never_ask_for_auth ;
121121 // 1. serve stage (static files|reverse proxy)
122122 if Method :: CONNECT != req. method ( ) {
123- let req_basic = extract_requst_basic_info (
123+ let origin_scheme_host_port = extract_requst_basic_info (
124124 & req,
125125 match self . config . over_tls {
126126 true => "https" ,
@@ -130,15 +130,15 @@ impl ProxyHandler {
130130 if let Some ( locations) = self
131131 . config
132132 . reverse_proxy_config
133- . get ( & req_basic . host )
133+ . get ( & origin_scheme_host_port . host )
134134 . or ( self . config . reverse_proxy_config . get ( DEFAULT_HOST ) )
135135 {
136136 if let Some ( location_config) = pick_location ( req. uri ( ) . path ( ) , locations) {
137137 let upstream_req = build_upstream_req ( req, location_config) ?;
138138 info ! (
139139 "[reverse proxy] {:^35} => {}{}** ==> [{}] {:?} [{:?}]" ,
140140 SocketAddrFormat ( & client_socket_addr) . to_string( ) ,
141- req_basic ,
141+ origin_scheme_host_port ,
142142 location_config. location,
143143 upstream_req. method( ) ,
144144 & upstream_req. uri( ) ,
@@ -148,6 +148,7 @@ impl ProxyHandler {
148148 . reverse_proxy_req
149149 . get_or_create ( & LabelImpl :: new ( ReverseProxyReqLabel {
150150 client : client_socket_addr. ip ( ) . to_canonical ( ) . to_string ( ) ,
151+ origin : origin_scheme_host_port. to_string ( ) + location_config. location . as_str ( ) ,
151152 upstream : location_config. upstream . scheme_and_authority . clone ( )
152153 + location_config. upstream . replacement . as_str ( ) ,
153154 } ) )
@@ -158,7 +159,7 @@ impl ProxyHandler {
158159 . inc ( ) ;
159160 let context = ReverseReqContext {
160161 upstream : & location_config. upstream ,
161- oringin_req_basic : & req_basic ,
162+ origin_scheme_host_port : & origin_scheme_host_port ,
162163 } ;
163164 return self . reverse_proxy ( upstream_req, & context) . await ;
164165 }
@@ -387,7 +388,7 @@ impl ProxyHandler {
387388
388389 let absolute_redirect_location = ensure_absolute ( redirect_location, context) ?;
389390 if let Some ( replacement) = lookup_replacement (
390- context. oringin_req_basic ,
391+ context. origin_scheme_host_port ,
391392 absolute_redirect_location,
392393 & self . redirect_bachpaths ,
393394 ) {
@@ -545,13 +546,13 @@ fn build_upstream_req(
545546 . map_err ( |e| io:: Error :: new ( ErrorKind :: InvalidData , e) )
546547}
547548
548- struct ReqBasic {
549+ struct SchemeHostPort {
549550 scheme : String ,
550551 host : String ,
551552 port : Option < u16 > ,
552553}
553554
554- impl Display for ReqBasic {
555+ impl Display for SchemeHostPort {
555556 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
556557 match self . port {
557558 Some ( port) => write ! ( f, "{}://{}:{}" , self . scheme, self . host, port) ,
@@ -563,12 +564,12 @@ impl Display for ReqBasic {
563564fn extract_requst_basic_info (
564565 req : & Request < Incoming > ,
565566 default_scheme : & str ,
566- ) -> io:: Result < ReqBasic > {
567+ ) -> io:: Result < SchemeHostPort > {
567568 let uri = req. uri ( ) ;
568569 let scheme = uri. scheme_str ( ) . unwrap_or ( default_scheme) ;
569570 if req. version ( ) == Version :: HTTP_2 {
570571 //H2,信息全在uri中
571- Ok ( ReqBasic {
572+ Ok ( SchemeHostPort {
572573 scheme : scheme. to_owned ( ) ,
573574 host : uri
574575 . host ( )
@@ -601,7 +602,7 @@ fn extract_requst_basic_info(
601602 ) ,
602603 None => None ,
603604 } ;
604- Ok ( ReqBasic {
605+ Ok ( SchemeHostPort {
605606 scheme : scheme. to_owned ( ) ,
606607 host,
607608 port,
@@ -625,7 +626,7 @@ fn is_schema_secure(uri: &Uri) -> bool {
625626
626627struct ReverseReqContext < ' a > {
627628 upstream : & ' a Upstream ,
628- oringin_req_basic : & ' a ReqBasic ,
629+ origin_scheme_host_port : & ' a SchemeHostPort ,
629630}
630631
631632struct RedirectBackpaths {
@@ -635,7 +636,7 @@ struct RedirectBackpaths {
635636}
636637
637638fn lookup_replacement (
638- req_basic : & ReqBasic ,
639+ origin_scheme_host_port : & SchemeHostPort ,
639640 absolute_redirect_location : String ,
640641 redirect_bachpaths : & [ RedirectBackpaths ] ,
641642) -> Option < String > {
@@ -647,16 +648,16 @@ fn lookup_replacement(
647648 format!( "*://{}:*{}**" , ele. host, ele. location) ,
648649 ) ;
649650 let host = match ele. host . as_str ( ) {
650- DEFAULT_HOST => & req_basic . host , // 如果是default_host,就用当前host
651+ DEFAULT_HOST => & origin_scheme_host_port . host , // 如果是default_host,就用当前host
651652 other => other,
652653 } ;
653- let port_part = if let Some ( port) = req_basic . port {
654+ let port_part = if let Some ( port) = origin_scheme_host_port . port {
654655 format ! ( ":{}" , port)
655656 } else {
656657 String :: new ( )
657658 } ;
658659 return Some (
659- req_basic . scheme . to_owned ( ) // use raw request's scheme
660+ origin_scheme_host_port . scheme . to_owned ( ) // use raw request's scheme
660661 + "://"
661662 + host // if it's default_host, use raw request's host
662663 + & port_part // use raw request's port if available
@@ -875,13 +876,15 @@ pub struct AccessLabel {
875876#[ derive( Clone , Debug , Hash , PartialEq , Eq , EncodeLabelSet , PartialOrd , Ord ) ]
876877pub struct ReverseProxyReqLabel {
877878 pub client : String ,
879+ pub origin : String ,
878880 pub upstream : String ,
879881}
880882
881883static ALL_REVERSE_PROXY_REQ : LazyLock < prom_label:: LabelImpl < ReverseProxyReqLabel > > =
882884 LazyLock :: new ( || {
883885 LabelImpl :: new ( ReverseProxyReqLabel {
884886 client : "all" . to_string ( ) ,
887+ origin : "all" . to_string ( ) ,
885888 upstream : "all" . to_string ( ) ,
886889 } )
887890 } ) ;
0 commit comments