Handler to serve files and resources.
Serves files from a given resource URL base and implements
the GET, HEAD, DELETE, OPTIONS, PUT, MOVE methods and the
IfModifiedSince and IfUnmodifiedSince header fields.
A simple memory cache is also provided to reduce file I/O.
HTTP/1.1 ranges are supported.
getAllowedMethods
public String[] getAllowedMethods()
getAllowedString
public String getAllowedString()
getMinGzipLength
public int getMinGzipLength()
Get minimum content length for GZIP encoding.
- Minimum length of content for gzip encoding or -1 if disabled.
getRedirectWelcome
public boolean getRedirectWelcome()
- True if welcome files are redirected to. False if forward is used.
getResource
protected Resource getResource(String pathInContext)
throws IOException
get Resource to serve.
Map a path to a resource. The default implementation calls
HttpContext.getResource but derived handers may provide
their own mapping.
pathInContext
- The path to find a resource for.
handle
public void handle(String pathInContext,
String pathParams,
HttpRequest request,
HttpResponse response)
throws HttpException,
IOException
Handle a request.
Note that Handlers are tried in order until one has handled the
request. i.e. until request.isHandled() returns true.
In broad terms this means, either a response has been commited
or request.setHandled(true) has been called.
- handle in interface HttpHandler
pathInContext
- The context pathpathParams
- Path parameters such as encoded Session IDrequest
- The HttpRequest requestresponse
- The HttpResponse response
isAcceptRanges
public boolean isAcceptRanges()
isDirAllowed
public boolean isDirAllowed()
isMethodAllowed
public boolean isMethodAllowed(String method)
setAcceptRanges
public void setAcceptRanges(boolean ar)
Set if the handler accepts range requests.
Default is false;
ar
- True if the handler should accept ranges
setAllowedMethods
public void setAllowedMethods(String[] methods)
setDirAllowed
public void setDirAllowed(boolean dirAllowed)
setMinGzipLength
public void setMinGzipLength(int minGzipLength)
Set minimum content length for GZIP encoding.
minGzipLength
- If set to a positive integer, then static content
larger than this will be served as gzip content encoded
if a matching resource is found ending with ".gz"
setRedirectWelcome
public void setRedirectWelcome(boolean redirectWelcome)
redirectWelcome
- True if welcome files are redirected to. False
if forward is used.
writeHeaders
public void writeHeaders(HttpResponse response,
Resource resource,
long count)
throws IOException