Convert (if necessary) and return the absolute URL that represents the resource referenced by this possibly relative URL. If this URL is already absolute, return it unchanged. @param location URL to be (possibly) converted and then returned @return the absolute URL @exception IllegalArgumentExcep
(String location)
| 1425 | * absolute one |
| 1426 | */ |
| 1427 | protected String toAbsolute(String location) { |
| 1428 | |
| 1429 | if (location == null) { |
| 1430 | return null; |
| 1431 | } |
| 1432 | |
| 1433 | boolean leadingSlash = location.startsWith("/"); |
| 1434 | |
| 1435 | if (location.startsWith("//")) { |
| 1436 | // Scheme relative |
| 1437 | redirectURLCC.recycle(); |
| 1438 | // Add the scheme |
| 1439 | String scheme = request.getScheme(); |
| 1440 | try { |
| 1441 | redirectURLCC.append(scheme, 0, scheme.length()); |
| 1442 | redirectURLCC.append(':'); |
| 1443 | redirectURLCC.append(location, 0, location.length()); |
| 1444 | return redirectURLCC.toString(); |
| 1445 | } catch (IOException ioe) { |
| 1446 | throw new IllegalArgumentException(location, ioe); |
| 1447 | } |
| 1448 | |
| 1449 | } else if (leadingSlash || !UriUtil.hasScheme(location)) { |
| 1450 | |
| 1451 | redirectURLCC.recycle(); |
| 1452 | |
| 1453 | String scheme = request.getScheme(); |
| 1454 | String name = request.getServerName(); |
| 1455 | int port = request.getServerPort(); |
| 1456 | |
| 1457 | try { |
| 1458 | redirectURLCC.append(scheme, 0, scheme.length()); |
| 1459 | redirectURLCC.append("://", 0, 3); |
| 1460 | redirectURLCC.append(name, 0, name.length()); |
| 1461 | if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) { |
| 1462 | redirectURLCC.append(':'); |
| 1463 | String portS = port + ""; |
| 1464 | redirectURLCC.append(portS, 0, portS.length()); |
| 1465 | } |
| 1466 | if (!leadingSlash) { |
| 1467 | String relativePath = request.getDecodedRequestURI(); |
| 1468 | int pos = relativePath.lastIndexOf('/'); |
| 1469 | CharChunk encodedURI = urlEncoder.encodeURL(relativePath, 0, pos); |
| 1470 | redirectURLCC.append(encodedURI); |
| 1471 | encodedURI.recycle(); |
| 1472 | redirectURLCC.append('/'); |
| 1473 | } |
| 1474 | redirectURLCC.append(location, 0, location.length()); |
| 1475 | |
| 1476 | normalize(redirectURLCC); |
| 1477 | } catch (IOException ioe) { |
| 1478 | throw new IllegalArgumentException(location, ioe); |
| 1479 | } |
| 1480 | |
| 1481 | return redirectURLCC.toString(); |
| 1482 | |
| 1483 | } else { |
| 1484 |