MCPcopy Create free account
hub / github.com/apache/tomcat / toAbsolute

Method toAbsolute

java/org/apache/catalina/connector/Response.java:1427–1489  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 15

testBug53062aMethod · 0.95
testBug53062bMethod · 0.95
testBug53062cMethod · 0.95
testBug53062dMethod · 0.95
testBug53062eMethod · 0.95
testBug53062fMethod · 0.95
testBug53062gMethod · 0.95
testBug53062hMethod · 0.95
testBug53062iMethod · 0.95
testBug53062jMethod · 0.95
testBug53062kMethod · 0.95
testBug53062lMethod · 0.95

Calls 13

hasSchemeMethod · 0.95
normalizeMethod · 0.95
lengthMethod · 0.80
recycleMethod · 0.65
getSchemeMethod · 0.65
toStringMethod · 0.65
getServerNameMethod · 0.65
getServerPortMethod · 0.65
equalsMethod · 0.65
encodeURLMethod · 0.65
startsWithMethod · 0.45
appendMethod · 0.45

Tested by 15

testBug53062aMethod · 0.76
testBug53062bMethod · 0.76
testBug53062cMethod · 0.76
testBug53062dMethod · 0.76
testBug53062eMethod · 0.76
testBug53062fMethod · 0.76
testBug53062gMethod · 0.76
testBug53062hMethod · 0.76
testBug53062iMethod · 0.76
testBug53062jMethod · 0.76
testBug53062kMethod · 0.76
testBug53062lMethod · 0.76