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

Make the core ResourceService a bit more reusable for subclasses #12281

Draft
wants to merge 1 commit into
base: jetty-12.0.x
Choose a base branch
from
Draft
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 @@ -47,6 +47,7 @@
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.resource.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -623,7 +624,7 @@ private void sendDirectory(Request request, Response response, HttpContent httpC
}

String base = URIUtil.addEncodedPaths(request.getHttpURI().getPath(), "/");
String listing = ResourceListing.getAsXHTML(httpContent.getResource(), base, pathInContext.length() > 1, request.getHttpURI().getQuery());
String listing = ResourceListing.getAsXHTML(getSendDirectoryResource(httpContent), base, pathInContext.length() > 1, request.getHttpURI().getQuery());
if (listing == null)
{
writeHttpError(request, response, callback, HttpStatus.FORBIDDEN_403);
Expand All @@ -638,7 +639,18 @@ private void sendDirectory(Request request, Response response, HttpContent httpC
response.write(true, ByteBuffer.wrap(data), callback);
}

private void sendData(Request request, Response response, Callback callback, HttpContent content, List<String> reqRanges) throws IOException
/**
* Allows a subclass to customize a resource used for XHTML directory listings.
*
* @param httpContent the source HttpContent.
* @return By default, {@link HttpContent#getResource()}, may be null.
*/
protected Resource getSendDirectoryResource(final HttpContent httpContent)
{
return httpContent.getResource();
}

protected void sendData(Request request, Response response, Callback callback, HttpContent content, List<String> reqRanges)
{
if (LOG.isDebugEnabled())
{
Expand Down
Loading