@@ -321,14 +321,18 @@ public boolean containsHeader(String name)
321
321
@ Override
322
322
public String encodeURL (String url )
323
323
{
324
+ if (url == null )
325
+ return null ;
326
+
324
327
final Request request = _channel .getRequest ();
325
328
SessionHandler sessionManager = request .getSessionHandler ();
326
329
327
330
if (sessionManager == null )
328
331
return url ;
329
332
330
333
HttpURI uri = null ;
331
- if (sessionManager .isCheckingRemoteSessionIdEncoding () && URIUtil .hasScheme (url ))
334
+ boolean hasScheme = URIUtil .hasScheme (url );
335
+ if (sessionManager .isCheckingRemoteSessionIdEncoding () && hasScheme )
332
336
{
333
337
uri = new HttpURI (url );
334
338
String path = uri .getPath ();
@@ -350,9 +354,6 @@ public String encodeURL(String url)
350
354
if (sessionURLPrefix == null )
351
355
return url ;
352
356
353
- if (url == null )
354
- return null ;
355
-
356
357
// should not encode if cookies in evidence
357
358
if ((sessionManager .isUsingCookies () && request .isRequestedSessionIdFromCookie ()) || !sessionManager .isUsingURLs ())
358
359
{
@@ -383,9 +384,6 @@ public String encodeURL(String url)
383
384
384
385
String id = sessionManager .getExtendedId (session );
385
386
386
- if (uri == null )
387
- uri = new HttpURI (url );
388
-
389
387
// Already encoded
390
388
int prefix = url .indexOf (sessionURLPrefix );
391
389
if (prefix != -1 )
@@ -400,20 +398,24 @@ public String encodeURL(String url)
400
398
url .substring (suffix );
401
399
}
402
400
401
+ // check for a null path
402
+ String nonNullPath = "" ;
403
+ if (hasScheme )
404
+ {
405
+ if (uri == null )
406
+ uri = new HttpURI (url );
407
+ if (uri .getPath () == null )
408
+ nonNullPath = "/" ;
409
+ }
410
+
403
411
// edit the session
404
412
int suffix = url .indexOf ('?' );
405
413
if (suffix < 0 )
406
414
suffix = url .indexOf ('#' );
407
415
if (suffix < 0 )
408
- {
409
- return url +
410
- ((HttpScheme .HTTPS .is (uri .getScheme ()) || HttpScheme .HTTP .is (uri .getScheme ())) && uri .getPath () == null ? "/" : "" ) + //if no path, insert the root path
411
- sessionURLPrefix + id ;
412
- }
416
+ return url + nonNullPath + sessionURLPrefix + id ;
413
417
414
- return url .substring (0 , suffix ) +
415
- ((HttpScheme .HTTPS .is (uri .getScheme ()) || HttpScheme .HTTP .is (uri .getScheme ())) && uri .getPath () == null ? "/" : "" ) + //if no path so insert the root path
416
- sessionURLPrefix + id + url .substring (suffix );
418
+ return url .substring (0 , suffix ) + nonNullPath + sessionURLPrefix + id + url .substring (suffix );
417
419
}
418
420
419
421
@ Override
0 commit comments