Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetty 12 - General cleanup of URIUtil #8861

Merged
merged 9 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.eclipse.jetty.util.FileID;
import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.component.Environment;
Expand Down Expand Up @@ -481,15 +480,15 @@ protected void initializeContextPath(ContextHandler context, Path path)
// special case of archive (or dir) named "root" is / context
if (contextPath.equalsIgnoreCase("root"))
{
contextPath = URIUtil.SLASH;
contextPath = "/";
}
// handle root with virtual host form
else if (StringUtil.startsWithIgnoreCase(contextPath, "root-"))
{
int dash = contextPath.indexOf('-');
String virtual = contextPath.substring(dash + 1);
context.setVirtualHosts(Arrays.asList(virtual.split(",")));
contextPath = URIUtil.SLASH;
contextPath = "/";
}

// Ensure "/" is Prepended to all context paths.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.FileID;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.Environment;

Expand Down Expand Up @@ -71,7 +70,7 @@ public ContextHandler createContextHandler(App app)

// special case of archive (or dir) named "root" is / context
if (path.equalsIgnoreCase("root") || path.equalsIgnoreCase("root/"))
path = URIUtil.SLASH;
path = "/";

// Ensure "/" is Prepended to all context paths.
if (path.charAt(0) != '/')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ public static String relativePath(String base,

if (info.startsWith("./"))
info = info.substring(2);
if (base.endsWith(URIUtil.SLASH))
if (info.startsWith(URIUtil.SLASH))
if (base.endsWith("/"))
if (info.startsWith("/"))
path = base + info.substring(1);
else
path = base + info;
else if (info.startsWith(URIUtil.SLASH))
else if (info.startsWith("/"))
path = base + info;
else
path = base + URIUtil.SLASH + info;
path = base + "/" + info;
return path;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public static String getAsXHTML(Resource resource, String base, boolean parent,

// Ensure name has a slash if it's a directory
if (item.isDirectory() && !name.endsWith("/"))
name += URIUtil.SLASH;
name += "/";

// Name
buf.append("<tr><td class=\"name\"><a href=\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void doGet(Request request, Response response, Callback callback, HttpCon
// Is this a Range request?
List<String> reqRanges = request.getHeaders().getValuesList(HttpHeader.RANGE.asString());

boolean endsWithSlash = pathInContext.endsWith(URIUtil.SLASH);
boolean endsWithSlash = pathInContext.endsWith("/");
boolean checkPrecompressedVariants = _precompressedFormats.size() > 0 && !endsWithSlash && reqRanges.isEmpty();

try
Expand Down Expand Up @@ -552,7 +552,7 @@ private void sendDirectory(Request request, Response response, HttpContent httpC
return;
}

String base = URIUtil.addEncodedPaths(request.getHttpURI().getPath(), URIUtil.SLASH);
String base = URIUtil.addEncodedPaths(request.getHttpURI().getPath(), "/");
String listing = ResourceListing.getAsXHTML(httpContent.getResource(), base, pathInContext.length() > 1, request.getHttpURI().getQuery());
if (listing == null)
{
Expand Down
Loading