changeset 470:a9862e2aacaa

ST-50
author Devel 1
date Thu, 03 Aug 2017 14:59:41 +0200
parents ef2c26e83b32
children 34545d3acba8
files stress-tester/src/main/java/com/passus/st/client/http/filter/HttpAbstractCleanerFilter.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpRequestCacheHeadersCleanerFilter.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpRequestProxyHeadersCleanerFilter.java
diffstat 3 files changed, 74 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpAbstractCleanerFilter.java	Thu Aug 03 14:59:41 2017 +0200
@@ -0,0 +1,33 @@
+package com.passus.st.client.http.filter;
+
+import com.passus.data.ByteString;
+import com.passus.net.http.HttpHeaders;
+import com.passus.net.http.HttpRequest;
+import com.passus.net.http.HttpResponse;
+import com.passus.st.client.http.HttpFlowContext;
+import static com.passus.st.client.http.filter.HttpFilter.DUNNO;
+
+/**
+ *
+ * @author mikolaj.podbielski
+ */
+public abstract class HttpAbstractCleanerFilter extends HttpFilter {
+
+    private final ByteString[] headerNames;
+
+    public HttpAbstractCleanerFilter(ByteString[] headerNames) {
+        this.headerNames = headerNames;
+    }
+
+    @Override
+    public int filterOutbound(HttpRequest request, HttpResponse resp, HttpFlowContext context) {
+        if (request != null) {
+            HttpHeaders headers = request.getHeaders();
+            for (ByteString headerName : headerNames) {
+                headers.delete(headerName);
+            }
+        }
+
+        return DUNNO;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpRequestCacheHeadersCleanerFilter.java	Thu Aug 03 14:59:41 2017 +0200
@@ -0,0 +1,30 @@
+package com.passus.st.client.http.filter;
+
+import com.passus.commons.annotations.Plugin;
+import com.passus.data.ByteString;
+import com.passus.st.plugin.PluginConstants;
+
+/**
+ *
+ * @author mikolaj.podbielski
+ */
+@Plugin(name = HttpRequestCacheHeadersCleanerFilter.TYPE, category = PluginConstants.CATEGORY_HTTP_FILTER)
+public class HttpRequestCacheHeadersCleanerFilter extends HttpAbstractCleanerFilter {
+
+    public static final String TYPE = "requestCacheHeadersCleaner";
+
+    public static final ByteString[] CACHE_HEADERS = {
+        ByteString.create("If-Modified-Since"),
+        ByteString.create("If-None-Match")
+    };
+
+    public HttpRequestCacheHeadersCleanerFilter() {
+        super(CACHE_HEADERS);
+    }
+
+    @Override
+    public HttpFilter instanceForWorker(int index) {
+        return new HttpRequestCacheHeadersCleanerFilter();
+    }
+
+}
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpRequestProxyHeadersCleanerFilter.java	Thu Aug 03 14:41:07 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpRequestProxyHeadersCleanerFilter.java	Thu Aug 03 14:59:41 2017 +0200
@@ -2,46 +2,28 @@
 
 import com.passus.commons.annotations.Plugin;
 import com.passus.data.ByteString;
-import com.passus.net.http.HttpHeaders;
-import com.passus.net.http.HttpRequest;
-import com.passus.net.http.HttpResponse;
-import com.passus.st.client.http.HttpFlowContext;
 import com.passus.st.plugin.PluginConstants;
-import java.util.HashSet;
-import java.util.Set;
 
 /**
  *
  * @author Mirosław Hawrot
  */
 @Plugin(name = HttpRequestProxyHeadersCleanerFilter.TYPE, category = PluginConstants.CATEGORY_HTTP_FILTER)
-public class HttpRequestProxyHeadersCleanerFilter extends HttpFilter {
+public class HttpRequestProxyHeadersCleanerFilter extends HttpAbstractCleanerFilter {
 
     public static final String TYPE = "requestProxyHeadersCleaner";
 
-    public static final ByteString[] PROXY_HEADERS;
+    public static final ByteString[] PROXY_HEADERS = {
+        ByteString.create("Forwarded"),
+        ByteString.create("Proxy-Authorization"),
+        ByteString.create("X-Forwarded-For"),
+        ByteString.create("X-Forwarded-Host"),
+        ByteString.create("X-Forwarded-Proto"),
+        ByteString.create("Proxy-Connection")
+    };
 
-    static {
-        Set<ByteString> reqProxyHeaders = new HashSet<>();
-        reqProxyHeaders.add(ByteString.create("Forwarded"));
-        reqProxyHeaders.add(ByteString.create("Proxy-Authorization"));
-        reqProxyHeaders.add(ByteString.create("X-Forwarded-For"));
-        reqProxyHeaders.add(ByteString.create("X-Forwarded-Host"));
-        reqProxyHeaders.add(ByteString.create("X-Forwarded-Proto"));
-        reqProxyHeaders.add(ByteString.create("Proxy-Connection"));
-        PROXY_HEADERS = reqProxyHeaders.toArray(new ByteString[]{});
-    }
-
-    @Override
-    public int filterOutbound(HttpRequest request, HttpResponse resp, HttpFlowContext context) {
-        if (request != null) {
-            HttpHeaders headers = request.getHeaders();
-            for (ByteString headerName : PROXY_HEADERS) {
-                headers.delete(headerName);
-            }
-        }
-
-        return DUNNO;
+    public HttpRequestProxyHeadersCleanerFilter() {
+        super(PROXY_HEADERS);
     }
 
     @Override