@@ -17,7 +17,8 @@ use warp::{
1717 BoxedFilter ,
1818 path:: { FullPath , Tail } ,
1919 } ,
20- http:: { HeaderMap , StatusCode } ,
20+ host:: Authority ,
21+ http:: { HeaderMap , HeaderValue , StatusCode } ,
2122 reject:: Rejection ,
2223} ;
2324
@@ -116,18 +117,26 @@ pub trait HttpSource: Clone + Send + Sync + 'static {
116117 . and ( warp:: path:: full ( ) )
117118 . and ( warp:: header:: optional :: < String > ( "content-encoding" ) )
118119 . and ( warp:: header:: headers_cloned ( ) )
120+ . and ( warp:: host:: optional ( ) )
119121 . and ( warp:: body:: bytes ( ) )
120122 . and ( warp:: query :: < HashMap < String , String > > ( ) )
121123 . and ( warp:: filters:: ext:: optional ( ) )
122124 . and_then (
123125 move |path : FullPath ,
124126 encoding_header : Option < String > ,
125- headers : HeaderMap ,
127+ mut headers : HeaderMap ,
128+ host : Option < Authority > ,
126129 body : Bytes ,
127130 query_parameters : HashMap < String , String > ,
128131 addr : Option < PeerAddr > | {
129132 debug ! ( message = "Handling HTTP request." , headers = ?headers) ;
130133 let http_path = path. as_str ( ) ;
134+ if !headers. contains_key ( "host" ) && let Some ( host) = host {
135+ // Put authority into the "host" header for compatibility with HTTP/2.
136+ let host_header = HeaderValue :: from_str ( host. as_str ( ) )
137+ . expect ( "authority is valid header" ) ;
138+ headers. insert ( "host" , host_header) ;
139+ }
131140 let events = auth_matcher
132141 . as_ref ( )
133142 . map_or ( Ok ( ( ) ) , |a| {
0 commit comments