Reputation: 344
I'am using Apache NiFi for a small webservice that should be able to serve static files(HTML, JavaScript, PNG, SVG, CSS). I have encountered an issue since NiFi not seems to set the Content-Type in the response header.
How can I configure the HandleHttpResponse-module to set the Content-Type header properly based on the requested filetype?
One way to do it is to use nested ifElse-statements in Expression Language but I don't think that would be best practice?
What I'am trying to achieve is that it should set Content-Type to image/svg+xml
if the requested file is an SVG file, text/css
if the requested file is an CSS-file etc.
Thanks in advance!
Upvotes: 1
Views: 904
Reputation: 28634
use LookupAttribute processor
put into SimpleKeyValueLookupService the map of file extension and Content-Type
svg = image/svg+xml
css = text/css
...
configure LookupAttribute to use SimpleKeyValueLookupService and set the dynamic property:
mime.type = ${filename:replaceAll('.*\\.([^\\.]+)$','$1')}
Upvotes: 2