@@ -342,14 +342,18 @@ public boolean containsHeader(String name)
342
342
@ Override
343
343
public String encodeURL (String url )
344
344
{
345
+ if (url == null )
346
+ return null ;
347
+
345
348
final Request request = _channel .getRequest ();
346
349
SessionHandler sessionManager = request .getSessionHandler ();
347
350
348
351
if (sessionManager == null )
349
352
return url ;
350
353
351
354
HttpURI uri = null ;
352
- if (sessionManager .isCheckingRemoteSessionIdEncoding () && URIUtil .hasScheme (url ))
355
+ boolean hasScheme = URIUtil .hasScheme (url );
356
+ if (sessionManager .isCheckingRemoteSessionIdEncoding () && hasScheme )
353
357
{
354
358
uri = HttpURI .from (url );
355
359
String path = uri .getPath ();
@@ -371,9 +375,6 @@ public String encodeURL(String url)
371
375
if (sessionURLPrefix == null )
372
376
return url ;
373
377
374
- if (url == null )
375
- return null ;
376
-
377
378
// should not encode if cookies in evidence
378
379
if ((sessionManager .isUsingCookies () && request .isRequestedSessionIdFromCookie ()) || !sessionManager .isUsingURLs ())
379
380
{
@@ -404,9 +405,6 @@ public String encodeURL(String url)
404
405
405
406
String id = sessionManager .getExtendedId (session );
406
407
407
- if (uri == null )
408
- uri = HttpURI .from (url );
409
-
410
408
// Already encoded
411
409
int prefix = url .indexOf (sessionURLPrefix );
412
410
if (prefix != -1 )
@@ -421,20 +419,24 @@ public String encodeURL(String url)
421
419
url .substring (suffix );
422
420
}
423
421
422
+ // check for a null path
423
+ String nonNullPath = "" ;
424
+ if (hasScheme )
425
+ {
426
+ if (uri == null )
427
+ uri = HttpURI .from (url );
428
+ if (uri .getPath () == null )
429
+ nonNullPath = "/" ;
430
+ }
431
+
424
432
// edit the session
425
433
int suffix = url .indexOf ('?' );
426
434
if (suffix < 0 )
427
435
suffix = url .indexOf ('#' );
428
436
if (suffix < 0 )
429
- {
430
- return url +
431
- ((HttpScheme .HTTPS .is (uri .getScheme ()) || HttpScheme .HTTP .is (uri .getScheme ())) && uri .getPath () == null ? "/" : "" ) + //if no path, insert the root path
432
- sessionURLPrefix + id ;
433
- }
437
+ return url + nonNullPath + sessionURLPrefix + id ;
434
438
435
- return url .substring (0 , suffix ) +
436
- ((HttpScheme .HTTPS .is (uri .getScheme ()) || HttpScheme .HTTP .is (uri .getScheme ())) && uri .getPath () == null ? "/" : "" ) + //if no path so insert the root path
437
- sessionURLPrefix + id + url .substring (suffix );
439
+ return url .substring (0 , suffix ) + nonNullPath + sessionURLPrefix + id + url .substring (suffix );
438
440
}
439
441
440
442
@ Override
0 commit comments