FileReaderServlet
The FileReaderServlet returns the content of a specified file. The incoming pathInfo
will be taken as filename. The file has to be located in the configured root directory (RootDirectory
attribute).
The FileReaderServlet can be used to make static files accessible to the frontend. You can also use this servlet to configure files in the ErrorFilter to get static error pages via a servlet.
Files can be added, modified, or removed in the root directory while nevisProxy is running.
Do not put any sensitive files into the configured root directory or its subdirectories. These files may become visible to the frontend if the FileReaderServlet is mapped to a public URL.
ch::nevis::nevisproxy::servlet::file::FileReaderServlet
libNPFileServlets.so.1
Configuration
RootDirectory
Type: string
Usage Constraints: required
Example: /var/opt/nevisproxy/<instance>/files
Defines the directory where the files to be read are located. Both absolute and relative paths are supported.
If you configure a relative path, the path will be prefixed with <docBase>/WEB-INF/lib
, where <docBase>
refers to the configuration parameter docBase
in the Context section of the navajo.xml configuration file.
Files
Type: string
Syntax: <filename_regex>:<content-type>
Regexp type: PCRE
Usage Constraints: optional, conditional
Default pragma: Continue
Default:
^[^/]*\.ai$:application/postscript
^[^/]*\.aim$:application/x-aim
^[^/]*\.art$:image/x-jg
^[^/]*\.ico$:image/x-icon
^[^/]*\.bcpio$:application/x-bcpio
^[^/]*\.bin$:application/octet-stream
^[^/]*\.bmp$:image/bmp
^[^/]*\.body$:text/html
^[^/]*\.cer$:application/x-x509-ca-cert
^[^/]*\.class$:application/java
^[^/]*\.css$:text/css
^[^/]*\.dib$:image/bmp
^[^/]*\.doc$:application/msword
^[^/]*\.dtd$:text/plain
^[^/]*\.eps$:application/postscript
^[^/]*\.exe$:application/octet-stream
^[^/]*\.gif$:image/gif
^[^/]*\.gtar$:application/x-gtar
^[^/]*\.gz$:application/x-gzip
^[^/]*\.htm$:text/html
^[^/]*\.html$:text/html
^[^/]*\.ief$:image/ief
^[^/]*\.jar$:application/java-archive
^[^/]*\.java$:text/plain
^[^/]*\.jpe$:image/jpeg
^[^/]*\.jpeg$:image/jpeg
^[^/]*\.jpg$:image/jpeg
^[^/]*\.js$:text/javascript
^[^/]*\.jspf$:text/plain
^[^/]*\.latex$:application/x-latex
^[^/]*\.mpega$:audio/x-mpeg
^[^/]*\.mpg$:video/mpeg
^[^/]*\.pbm$:image/x-portable-bitmap
^[^/]*\.pct$:image/pict
^[^/]*\.pdf$:application/pdf
^[^/]*\.pgm$:image/x-portable-graymap
^[^/]*\.pic$:image/pict
^[^/]*\.pict$:image/pict
^[^/]*\.png$:image/png
^[^/]*\.pnm$:image/x-portable-anymap
^[^/]*\.ppm$:image/x-portable-pixmap
^[^/]*\.ps$:application/postscript
^[^/]*\.qti$:image/x-quicktime
^[^/]*\.qtif$:image/x-quicktime
^[^/]*\.ras$:image/x-cmu-raster
^[^/]*\.rgb$:image/x-rgb
^[^/]*\.swf$:application/x-shockwave-flash
^[^/]*\.tar$:application/x-tar
^[^/]*\.tif$:image/tiff
^[^/]*\.tiff$:image/tiff
^[^/]*\.txt$:text/plain
^[^/]*\.xbm$:image/x-xbitmap
^[^/]*\.xml$:text/xml
^[^/]*\.xpm$:image/x-xpixmap
^[^/]*\.xsl$:text/xml
^[^/]*\.svg$:image/svg+xml
^[^/]*\.Z$:application/x-compress
^[^/]*\.z$:application/x-compress
^[^/]*\.zip$:application/zip
^[^/]*\.woff$:font/woff
^[^/]*\.woff2$:font/woff2
^[^/]*\.eot$:application/vnd.ms-fontobject
^[^/]*\.ttf$:font/ttf
Specifies which files are served from the RootDirectory
and which Content-Type
is associated with them:
<filename_regex>
: The frontend can request files whose filenames (starting from the configured root directory) match this regex<content-type>
: TheContent-Type
header of the response sent to the frontend
Be aware that the regex is a PCRE regex, not a wildcard one. An expression such as the following one will not work: *.xml
.
The default configuration only allows to serve files directly located in the RootDirectory
. For example, proceed as follows to add the CSS files from the directory RootDirectory/css/
but not from its subdirectories:
- Add the parameter
Files
to your FileReaderServlet - Copy the default configuration for
Files
- Optional: Remove the lines for the unnecessary file types
- Add the following line:
^css/[^/]*\.css$:text/css
- Restart nevisProxy
DefaultFile
Type: string
Usage Constraints: optional
Defines the default file that is returned when the requested file doesn't exist or none of the rules in Files
matches the request's pathinfo.
The parameter's value is interpreted as relative to the RootDirectory
.
The Content-Type of the DefaultFile
is determined by matching the rules of Files
with the configured DefaultFile
value so in order to be able to deliver the DefaultFile
in a response, the Files
parameter must have a matching rule for DefaultFile
.
Profiles
If you want to enable serving files from the RootDirectory
and from its subdirectories, instead of the Files
parameter use the Profile AllowSubDirectories
. For example:
<servlet>
<servlet-name>AllowSubdirsFilesFileReaderServlet</servlet-name>
<servlet-class>ch::nevis::nevisproxy::servlet::file::FileReaderServlet</servlet-class>
<init-param>
<param-name>RootDirectory</param-name>
<param-value>/var/opt/nevisproxy/test/profiles</param-value>
</init-param>
<init-param>
<param-name>Profile</param-name>
<param-value>AllowSubDirectories</param-value>
</init-param>
</servlet>