Top Inners Fields Constructors Methods
io.undertow.server.handlers.resource

public Class ResourceHandler

extends Object
implements HttpHandler
Class Inheritance
All Implemented Interfaces
io.undertow.server.HttpHandler
Imports
java.io.File, .IOException, java.nio.file.Paths, java.util.Arrays, .Collections, .Date, .HashMap, .HashSet, .List, .Map, .Set, java.util.concurrent.CopyOnWriteArrayList, .TimeUnit, io.undertow.UndertowLogger, io.undertow.io.IoCallback, io.undertow.predicate.Predicate, .Predicates, io.undertow.server.HandlerWrapper, .HttpHandler, .HttpServerExchange, io.undertow.server.handlers.ResponseCodeHandler, io.undertow.server.handlers.builder.HandlerBuilder, io.undertow.server.handlers.cache.ResponseCache, io.undertow.server.handlers.encoding.ContentEncodedResource, .ContentEncodedResourceManager, io.undertow.util.ByteRange, .CanonicalPathUtils, .DateUtils, .ETag, .ETagUtils, .Headers, .HttpString, .Methods, .MimeMappings, .RedirectBuilder, .StatusCodes

Author
Stuart Douglas

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
private static class

Field Summary

Modifier and TypeField and Description
private volatile Predicate
private volatile Predicate
private volatile Integer
cacheTime

If this is set this will be the maximum time (in seconds) the client will cache the resource.

private volatile boolean
canonicalizePaths

If the canonical version of paths should be passed into the resource manager.

private volatile ContentEncodedResourceManager
private volatile boolean
directoryListingEnabled

If directory listing is enabled.

private static final Set<HttpString>
KNOWN_METHODS

Set of methods prescribed by HTTP 1.1.

private volatile MimeMappings
mimeMappings

The mime mappings that are used to determine the content type.

private final HttpHandler
next

Handler that is called if no resource is found

private volatile ResourceManager
private volatile ResourceSupplier
private final List<String>

Constructor Summary

AccessConstructor and Description
public
ResourceHandler(ResourceManager resourceSupplier)

public
public
public
public
ResourceHandler()
Deprecated

You should use ResourceHandler(ResourceManager) instead.

Method Summary

Modifier and TypeMethod and Description
public ResourceHandler
private String
private void
public Predicate
public Predicate
public Integer
public ContentEncodedResourceManager
private Resource
getIndexFiles(HttpServerExchange exchange, ResourceSupplier resourceManager, final String base, List<String> possible)

public MimeMappings
public ResourceManager
public ResourceSupplier
public void
handleRequest(final HttpServerExchange
the HTTP request/response exchange
exchange
)

Implements io.undertow.server.HttpHandler.handleRequest.

Handle the request.

public boolean
public boolean
private void
serveResource(final HttpServerExchange exchange, final boolean sendContent)

public ResourceHandler
setAllowed(final Predicate allowed)

public ResourceHandler
setCachable(final Predicate cachable)

public ResourceHandler
setCacheTime(final Integer cacheTime)

public void
setCanonicalizePaths(boolean
If paths should be canonicalized
canonicalizePaths
)

If this handler should use canonicalized paths.

public ResourceHandler
public ResourceHandler
setDirectoryListingEnabled(final boolean directoryListingEnabled)

public ResourceHandler
setMimeMappings(final MimeMappings mimeMappings)

public ResourceHandler
setResourceManager(final ResourceManager resourceManager)

public ResourceHandler
setResourceSupplier(final ResourceSupplier resourceSupplier)

public ResourceHandler
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allowedback to summary
private volatile Predicate allowed
cachableback to summary
private volatile Predicate cachable
cacheTimeback to summary
private volatile Integer cacheTime

If this is set this will be the maximum time (in seconds) the client will cache the resource.

Note

Do not set this for private resources, as it will cause a Cache-Control: public to be sent.

Todo

make this more flexible

This will only be used if the cachable predicate returns true

canonicalizePathsback to summary
private volatile boolean canonicalizePaths

If the canonical version of paths should be passed into the resource manager.

contentEncodedResourceManagerback to summary
private volatile ContentEncodedResourceManager contentEncodedResourceManager
directoryListingEnabledback to summary
private volatile boolean directoryListingEnabled

If directory listing is enabled.

KNOWN_METHODSback to summary
private static final Set<HttpString> KNOWN_METHODS

Set of methods prescribed by HTTP 1.1. If request method is not one of those, handler will return NOT_IMPLEMENTED.

mimeMappingsback to summary
private volatile MimeMappings mimeMappings

The mime mappings that are used to determine the content type.

nextback to summary
private final HttpHandler next

Handler that is called if no resource is found

resourceManagerback to summary
private volatile ResourceManager resourceManager
resourceSupplierback to summary
private volatile ResourceSupplier resourceSupplier
welcomeFilesback to summary
private final List<String> welcomeFiles

Constructor Detail

ResourceHandlerback to summary
public ResourceHandler(ResourceManager resourceSupplier)
ResourceHandlerback to summary
public ResourceHandler(ResourceManager resourceManager, HttpHandler next)
ResourceHandlerback to summary
public ResourceHandler(ResourceSupplier resourceSupplier)
ResourceHandlerback to summary
public ResourceHandler(ResourceSupplier resourceManager, HttpHandler next)
ResourceHandlerback to summary
public ResourceHandler()

Deprecated

You should use ResourceHandler(ResourceManager) instead.

Annotations
@Deprecated

Method Detail

addWelcomeFilesback to summary
public ResourceHandler addWelcomeFiles(String... files)
canonicalizeback to summary
private String canonicalize(String s)
clearCacheHeadersback to summary
private void clearCacheHeaders(HttpServerExchange exchange)
getAllowedback to summary
public Predicate getAllowed()
getCachableback to summary
public Predicate getCachable()
getCacheTimeback to summary
public Integer getCacheTime()
getContentEncodedResourceManagerback to summary
public ContentEncodedResourceManager getContentEncodedResourceManager()
getIndexFilesback to summary
private Resource getIndexFiles(HttpServerExchange exchange, ResourceSupplier resourceManager, final String base, List<String> possible) throws IOException
getMimeMappingsback to summary
public MimeMappings getMimeMappings()
getResourceManagerback to summary
public ResourceManager getResourceManager()
getResourceSupplierback to summary
public ResourceSupplier getResourceSupplier()
handleRequestback to summary
public void handleRequest(final HttpServerExchange exchange) throws Exception

Implements io.undertow.server.HttpHandler.handleRequest.

Doc from io.undertow.server.HttpHandler.handleRequest.

Handle the request.

Parameters
exchange:HttpServerExchange

the HTTP request/response exchange

Annotations
@Override
isCanonicalizePathsback to summary
public boolean isCanonicalizePaths()
isDirectoryListingEnabledback to summary
public boolean isDirectoryListingEnabled()
serveResourceback to summary
private void serveResource(final HttpServerExchange exchange, final boolean sendContent) throws Exception
setAllowedback to summary
public ResourceHandler setAllowed(final Predicate allowed)
setCachableback to summary
public ResourceHandler setCachable(final Predicate cachable)
setCacheTimeback to summary
public ResourceHandler setCacheTime(final Integer cacheTime)
setCanonicalizePathsback to summary
public void setCanonicalizePaths(boolean canonicalizePaths)

If this handler should use canonicalized paths.

Warning

If this is not true and io.undertow.server.handlers.CanonicalPathHandler is not installed in the handler chain then is may be possible to perform a directory traversal attack. If you set this to false make sure you have some kind of check in place to control the path.

Parameters
canonicalizePaths:boolean

If paths should be canonicalized

setContentEncodedResourceManagerback to summary
public ResourceHandler setContentEncodedResourceManager(ContentEncodedResourceManager contentEncodedResourceManager)
setDirectoryListingEnabledback to summary
public ResourceHandler setDirectoryListingEnabled(final boolean directoryListingEnabled)
setMimeMappingsback to summary
public ResourceHandler setMimeMappings(final MimeMappings mimeMappings)
setResourceManagerback to summary
public ResourceHandler setResourceManager(final ResourceManager resourceManager)
setResourceSupplierback to summary
public ResourceHandler setResourceSupplier(final ResourceSupplier resourceSupplier)
setWelcomeFilesback to summary
public ResourceHandler setWelcomeFiles(String... files)
io.undertow.server.handlers.resource back to summary

public Class ResourceHandler.Builder

extends Object
implements HandlerBuilder
Class Inheritance
All Implemented Interfaces
io.undertow.server.handlers.builder.HandlerBuilder

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public HandlerWrapper
build(Map<String, Object>
The handler config
config
)

Implements io.undertow.server.handlers.builder.HandlerBuilder.build.

Creates the handler

public String
public String
name()

Implements io.undertow.server.handlers.builder.HandlerBuilder.name.

The string representation of the handler name.

public Map<String, Class<?>>
parameters()

Implements io.undertow.server.handlers.builder.HandlerBuilder.parameters.

Returns a map of parameters and their types.

public Set<String>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Builderback to summary
public Builder()

Method Detail

buildback to summary
public HandlerWrapper build(Map<String, Object> config)

Implements io.undertow.server.handlers.builder.HandlerBuilder.build.

Doc from io.undertow.server.handlers.builder.HandlerBuilder.build.

Creates the handler

Parameters
config:Map<String, Object>

The handler config

Returns:HandlerWrapper

The new predicate

Annotations
@Override
defaultParameterback to summary
public String defaultParameter()

Implements io.undertow.server.handlers.builder.HandlerBuilder.defaultParameter.

Returns:String

Doc from io.undertow.server.handlers.builder.HandlerBuilder.defaultParameter.

The default parameter name, or null if it does not have a default parameter

Annotations
@Override
nameback to summary
public String name()

Implements io.undertow.server.handlers.builder.HandlerBuilder.name.

Doc from io.undertow.server.handlers.builder.HandlerBuilder.name.

The string representation of the handler name.

Returns:String

The handler name

Annotations
@Override
parametersback to summary
public Map<String, Class<?>> parameters()

Implements io.undertow.server.handlers.builder.HandlerBuilder.parameters.

Doc from io.undertow.server.handlers.builder.HandlerBuilder.parameters.

Returns a map of parameters and their types.

Annotations
@Override
requiredParametersback to summary
public Set<String> requiredParameters()

Implements io.undertow.server.handlers.builder.HandlerBuilder.requiredParameters.

Returns:Set<String>

Doc from io.undertow.server.handlers.builder.HandlerBuilder.requiredParameters.

The required parameters

Annotations
@Override
io.undertow.server.handlers.resource back to summary

private Class ResourceHandler.Wrapper

extends Object
implements HandlerWrapper
Class Inheritance
All Implemented Interfaces
io.undertow.server.HandlerWrapper

Field Summary

Modifier and TypeField and Description
private final boolean
private final String

Constructor Summary

AccessConstructor and Description
private
Wrapper(String location, boolean allowDirectoryListing)

Method Summary

Modifier and TypeMethod and Description
public HttpHandler
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allowDirectoryListingback to summary
private final boolean allowDirectoryListing
locationback to summary
private final String location

Constructor Detail

Wrapperback to summary
private Wrapper(String location, boolean allowDirectoryListing)

Method Detail

wrapback to summary
public HttpHandler wrap(HttpHandler handler)

Implements io.undertow.server.HandlerWrapper.wrap.

Annotations
@Override