alopresto commented on a change in pull request #4125: NIFI-7153 Adds
ContentLengthFilter and DoSFilter
URL: https://github.com/apache/nifi/pull/4125#discussion_r396868018
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
##########
@@ -655,6 +658,46 @@ private void addDocsServlets(WebAppContext docsContext) {
}
}
+ /**
+ * Adds configurable filters to the given context. Currently, this
implementation adds `DosFilter` and `ContentLengthFilter` filters.
+ * @param path path spec for filters
+ * @param webappContext context to which filters will be added
+ */
+ private void addFiltersWithProps(String path, WebAppContext webappContext)
{
+ int defaultMaxRequestsPerSecond =
Integer.parseInt(NiFiProperties.DEFAULT_WEB_MAX_REQUESTS_PER_SECOND);
+ int configuredMaxRequestsPerSecond = 0;
+ try {
+ configuredMaxRequestsPerSecond =
Integer.parseInt(props.getMaxWebRequestsPerSecond());
+ } catch (final NumberFormatException e) {
+ logger.warn("Exception parsing property " +
NiFiProperties.WEB_MAX_REQUESTS_PER_SECOND + "; using default value: " +
defaultMaxRequestsPerSecond);
+ }
+
+ int maxRequestsPerSecond = configuredMaxRequestsPerSecond > 0 ?
configuredMaxRequestsPerSecond : defaultMaxRequestsPerSecond;
+ FilterHolder holder = new FilterHolder(DoSFilter.class);
+ holder.setInitParameters(new HashMap<String, String>(){{
+ put("maxRequestsPerSec", String.valueOf(maxRequestsPerSecond));
+ }});
+ holder.setName(DoSFilter.class.getSimpleName());
+ logger.debug("Adding DoSFilter to context at path: " + path + " with
max req/sec: " + configuredMaxRequestsPerSecond);
+ webappContext.addFilter(holder, path,
EnumSet.allOf(DispatcherType.class));
+
+ int defaultMaxRequestSize =
DataUnit.parseDataSize(NiFiProperties.DEFAULT_WEB_MAX_CONTENT_SIZE,
DataUnit.B).intValue();
+ int configuredMaxRequestSize = 0;
+ try {
+ configuredMaxRequestSize =
DataUnit.parseDataSize(props.getWebMaxContentSize(), DataUnit.B).intValue();
+ } catch (final IllegalArgumentException e) {
+ logger.warn("Exception parsing property " +
NiFiProperties.WEB_MAX_CONTENT_SIZE + "; using default value: " +
defaultMaxRequestSize);
+ }
+
+ int maxRequestSize = configuredMaxRequestSize > 0 ?
configuredMaxRequestSize : defaultMaxRequestSize;
+ holder = new FilterHolder(ContentLengthFilter.class);
+ holder.setInitParameters(new HashMap<String, String>() {{
+ put("maxContentLength", String.valueOf(maxRequestSize));
+ }});
+ holder.setName(FilterHolder.class.getSimpleName());
+ logger.debug("Adding ContentLengthFilter to context at path: " + path
+ " with max request size: " + maxRequestSize + "B");
Review comment:
Add space between ordinal and unit (e.g. `maxRequestSize + " B"`).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services