apache-nifi - Set Content-type Apache NiFi dynamically
问题描述
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!
解决方案
使用LookupAttribute处理器
将文件扩展名和 Content-Type 的映射放入 SimpleKeyValueLookupService
svg = image/svg+xml
css = text/css
...
配置 LookupAttribute 以使用 SimpleKeyValueLookupService 并设置动态属性:
mime.type = ${filename:replaceAll('.*\\.([^\\.]+)$','$1')}
推荐阅读
- axios - 如何将 axios 设置为 Nuxt.js 的默认原型并将令牌附加到默认的 axios 授权标头?
- python - 如何使用 Python 将值存储在数组中
- r - 如何更改并排列出的两个表的特定列的外观(r markdown)
- python - CSV MNIST 数据集:ValueError:Shapes (None, 10) 和 (None, 28, 10) 不兼容
- python-3.x - 如何检测我的图像是否被截断并以线程安全的方式加载它?
- c++ - 定义一个全局变量模板?
- android - 当语言选择阿拉伯语时,如何设置短信验证布局的 RTL?
- javascript - 在没有“https”或“www”的情况下如何隔离URL的域名?
- firebase - Firebase 保留用户计数不匹配
- python - 我正在尝试学习从 API 请求、加载和解析 Json 数据。我收到一个值错误