Class StaticFiles
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAccess outcome for a resolved static file.static interfacestatic final classstatic interfacestatic interfacestatic interfacestatic interfacestatic interface -
Method Summary
Modifier and TypeMethodDescriptionmarshaledResponseFor(@NonNull String relativePath, @NonNull Request request) Produces a marshaled response forrelativePath, if the request targets a safe, readable file under the configured root.static @NonNull StaticFiles.BuilderBegins configuration for serving files underroot.
-
Method Details
-
withRoot
Begins configuration for serving files underroot.Relative roots are resolved against the JVM's current working directory when the builder is built. Production deployments should generally pass an absolute path.
File matching follows the underlying filesystem's case-sensitivity and Unicode normalization rules. Production deployments that need portable behavior across operating systems should standardize on ASCII-safe asset names.
- Parameters:
root- the static-file root directory- Returns:
- a builder for static-file responses
-
marshaledResponseFor
public @NonNull Optional<MarshaledResponse> marshaledResponseFor(@NonNull String relativePath, @NonNull Request request) Produces a marshaled response forrelativePath, if the request targets a safe, readable file under the configured root.Returns
Optional.empty()for HTTP methods other thanHttpMethod.GETandHttpMethod.HEAD, unsafe path input, directories without a configured index file, unreadable files, and missing files. Once a path resolves, non-200file responses such as206,304,412, and416are returned inside the optional.Resolvers receive the resolved file path after index-file resolution, not the original
relativePath.- Parameters:
relativePath- the root-relative file pathrequest- the incoming request- Returns:
- the marshaled response, if a static file was resolved
-