@@ -43,6 +43,9 @@ const MAX_SERVER_RETRY_INTERVAL: Duration = Duration::from_secs(60);
4343
4444static REPLAY_NONCE : http:: HeaderName = http:: HeaderName :: from_static ( "replay-nonce" ) ;
4545
46+ // Maximum number of redirects to follow for a single request.
47+ const MAX_REDIRECTS : usize = 10 ;
48+
4649pub enum NewAccountOutput < ' a > {
4750 Created ( & ' a str ) ,
4851 Found ( & ' a str ) ,
@@ -170,12 +173,29 @@ where
170173 }
171174
172175 pub async fn get ( & self , url : & Uri ) -> Result < http:: Response < Bytes > , RequestError > {
173- let req = http:: Request :: builder ( )
174- . uri ( url)
175- . method ( http:: Method :: GET )
176- . header ( http:: header:: CONTENT_LENGTH , 0 )
177- . body ( String :: new ( ) ) ?;
178- Ok ( self . http . request ( req) . await ?)
176+ let mut u = url. clone ( ) ;
177+
178+ for _ in 0 ..MAX_REDIRECTS {
179+ let req = http:: Request :: builder ( )
180+ . uri ( & u)
181+ . method ( http:: Method :: GET )
182+ . header ( http:: header:: CONTENT_LENGTH , 0 )
183+ . body ( String :: new ( ) ) ?;
184+ let res = self . http . request ( req) . await ?;
185+
186+ if res. status ( ) . is_redirection ( ) {
187+ if let Some ( location) = try_get_header ( res. headers ( ) , http:: header:: LOCATION ) {
188+ u = Uri :: try_from ( location) . map_err ( RequestError :: UrlParse ) ?;
189+ continue ;
190+ } else {
191+ return Err ( RequestError :: RedirectNoLocation ) ;
192+ }
193+ }
194+
195+ return Ok ( res) ;
196+ }
197+
198+ Err ( RequestError :: TooManyRedirects )
179199 }
180200
181201 pub async fn post < P : AsRef < [ u8 ] > > (
0 commit comments