@@ -230,56 +230,64 @@ public boolean isRedirected(final HttpRequest request, final HttpResponse respon
230230 " from proxy " + proxyRepository + " but no location present" );
231231 }
232232
233- final String repoId = proxyRepository . getId () ;
233+ boolean redirecting = true ;
234234
235- // Some complication here as it appears that something may be null, but its not clear what was null
236- URI sourceUri = ((HttpUriRequest ) request ).getURI ();
237- if (!sourceUri .isAbsolute ()) {
238- try {
239- sourceUri = URI .create (proxyRepository .getRemoteUrl ()).resolve (sourceUri );
240- }
241- catch (Exception e ) {
242- logger .debug ("[{}] Problem resolving {} against {}" , repoId , sourceUri , proxyRepository .getRemoteUrl ());
235+ final URI targetUri = createLocationURI (locationHeader .getValue ());
236+
237+ // this logic below should trigger only for content fetches made by RRS retrieveItem
238+ // hence, we do this ONLY if the HttpRequest is "marked" as such request
239+ if (Boolean .TRUE == context .getAttribute (HttpClientRemoteStorage .CONTENT_RETRIEVAL_MARKER_KEY )) {
240+ if (targetUri .getPath ().endsWith ("/" )) {
241+ redirecting = false ;
243242 }
244243 }
245244
246- final String sourceScheme = schemeOf (sourceUri );
247- final String sourceHost = hostOf (sourceUri );
245+ // Additional verification when debugging...
248246
249- final URI targetUri = createLocationURI (locationHeader .getValue ());
247+ if (logger .isDebugEnabled ()) {
248+ final String repoId = proxyRepository .getId ();
249+
250+ URI sourceUri = ((HttpUriRequest ) request ).getURI ();
251+ if (!sourceUri .isAbsolute ()) {
252+ try {
253+ sourceUri = URI .create (proxyRepository .getRemoteUrl ()).resolve (sourceUri );
254+ }
255+ catch (Exception e ) {
256+ logger .debug ("[{}] Problem resolving {} against {}" , repoId , sourceUri , proxyRepository .getRemoteUrl ());
257+ }
258+ }
250259
251- final String targetScheme = schemeOf (targetUri );
252- final String targetHost = hostOf (targetUri );
260+ final String sourceScheme = schemeOf (sourceUri );
261+ final String sourceHost = hostOf (sourceUri );
253262
254- final int redirectCode = response .getStatusLine ().getStatusCode ();
263+ final String targetScheme = schemeOf (targetUri );
264+ final String targetHost = hostOf (targetUri );
255265
256- // nag about redirection peculiarities, in any case
257- if (!Objects .equals (sourceScheme , targetScheme )) {
258- if ("http" .equals (targetScheme )) {
259- // security risk: HTTPS > HTTP downgrade, you are not safe as you think!
260- logger .debug ("[{}] Downgrade from HTTPS to HTTP during {} redirect {} -> {}" ,
261- repoId , redirectCode , sourceUri , targetUri );
262- }
263- else if ("https" .equals (targetScheme ) && Objects .equals (sourceHost , targetHost )) {
264- // misconfiguration: your repository configured with wrong protocol and causes performance problems?
265- logger .debug ("[{}] Protocol upgrade during {} redirect on same host {} -> {}" ,
266- repoId , redirectCode , sourceUri , targetUri );
266+ final int redirectCode = response .getStatusLine ().getStatusCode ();
267+
268+ // nag about redirection peculiarities, in any case
269+ if (!Objects .equals (sourceScheme , targetScheme )) {
270+ if ("http" .equals (targetScheme )) {
271+ // security risk: HTTPS > HTTP downgrade, you are not safe as you think!
272+ logger .debug ("[{}] Downgrade from HTTPS to HTTP during {} redirect {} -> {}" , repoId , redirectCode ,
273+ sourceUri , targetUri );
274+ }
275+ else if ("https" .equals (targetScheme ) && Objects .equals (sourceHost , targetHost )) {
276+ // misconfiguration: your repository configured with wrong protocol and causes performance problems?
277+ logger .debug ("[{}] Protocol upgrade during {} redirect on same host {} -> {}" , repoId , redirectCode ,
278+ sourceUri , targetUri );
279+ }
267280 }
268- }
269281
270- // this logic below should trigger only for content fetches made by RRS retrieveItem
271- // hence, we do this ONLY if the HttpRequest is "marked" as such request
272- if (Boolean .TRUE == context .getAttribute (HttpClientRemoteStorage .CONTENT_RETRIEVAL_MARKER_KEY )) {
273- if (targetUri .getPath ().endsWith ("/" )) {
274- logger .debug ("[{}] Not following {} redirect to index {} -> {}" ,
275- repoId , redirectCode , sourceUri , targetUri );
276- return false ;
282+ if (redirecting ) {
283+ logger .debug ("[{}] Following {} redirect {} -> {}" , repoId , redirectCode , sourceUri , targetUri );
284+ }
285+ else {
286+ logger .debug ("[{}] Not following {} redirect {} -> {}" , repoId , redirectCode , sourceUri , targetUri );
277287 }
278288 }
279289
280- logger .debug ("[{}] Following {} redirect {} -> {}" ,
281- repoId , redirectCode , sourceUri , targetUri );
282- return true ;
290+ return redirecting ;
283291 }
284292
285293 return false ;
0 commit comments