Commits

Sebastian Sdorra committed ee3c0e8

improve configuration of proxyservlet

  • Participants
  • Parent commits b01b966

Comments (0)

Files changed (2)

scm-core/src/main/java/sonia/scm/web/proxy/ProxyConfiguration.java

    *
    *
    * @param url
+   * @param copyRequestHeaders
    * @param requestHeaderExcludes
+   * @param copyResponseHeaders
    * @param responseHeaderExcludes
    * @param cacheEnabled
    */
-  public ProxyConfiguration(URL url, Set<String> requestHeaderExcludes,
+  public ProxyConfiguration(URL url, boolean copyRequestHeaders,
+    Set<String> requestHeaderExcludes, boolean copyResponseHeaders,
     Set<String> responseHeaderExcludes, boolean cacheEnabled)
   {
     this.url = url;
+    this.copyResponseHeaders = copyResponseHeaders;
     this.requestHeaderExcludes = requestHeaderExcludes;
+    this.copyResponseHeaders = copyResponseHeaders;
     this.responseHeaderExcludes = responseHeaderExcludes;
     this.cacheEnabled = cacheEnabled;
   }
     final ProxyConfiguration other = (ProxyConfiguration) obj;
 
     return Objects.equal(url, other.url)
+      && Objects.equal(copyRequestHeaders, other.copyRequestHeaders)
       && Objects.equal(requestHeaderExcludes, other.requestHeaderExcludes)
+      && Objects.equal(copyResponseHeaders, other.copyResponseHeaders)
       && Objects.equal(responseHeaderExcludes, other.responseHeaderExcludes)
       && Objects.equal(cacheEnabled, other.cacheEnabled);
   }
   @Override
   public int hashCode()
   {
-    return Objects.hashCode(url, requestHeaderExcludes, responseHeaderExcludes,
-      cacheEnabled);
+    return Objects.hashCode(url, copyRequestHeaders, requestHeaderExcludes,
+      copyResponseHeaders, responseHeaderExcludes, cacheEnabled);
   }
 
   /**
     //J-
     return Objects.toStringHelper(this)
                   .add("url", url)
+                  .add("copyRequestHeaders", copyRequestHeaders)
                   .add("requestHeaderExcludes", requestHeaderExcludes)
+                  .add("copyResponseHeaders", copyResponseHeaders)
                   .add("responseHeaderExcludes", responseHeaderExcludes)
                   .add("cacheEnabled", cacheEnabled)
                   .toString();
     return cacheEnabled;
   }
 
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
+  public boolean isCopyRequestHeaders()
+  {
+    return copyRequestHeaders;
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
+  public boolean isCopyResponseHeaders()
+  {
+    return copyResponseHeaders;
+  }
+
   //~--- fields ---------------------------------------------------------------
 
   /** Field description */
   private boolean cacheEnabled = true;
 
   /** Field description */
+  @XmlElement(name = "copy-request-headers")
+  private boolean copyRequestHeaders = true;
+
+  /** Field description */
+  @XmlElement(name = "copy-response-headers")
+  private boolean copyResponseHeaders = true;
+
+  /** Field description */
   @XmlElement(name = "exclude")
   @XmlElementWrapper(name = "request-header-excludes")
   private Set<String> requestHeaderExcludes;

scm-core/src/main/java/sonia/scm/web/proxy/ProxyServlet.java

 
       con = createConnection(configuration, request);
 
-      copyRequestHeaders(configuration, request, con);
+      if (configuration.isCopyRequestHeaders())
+      {
+        logger.trace("copy request headers");
+        copyRequestHeaders(configuration, request, con);
+      }
+      else
+      {
+        logger.trace("skip copy of request headers");
+      }
+
       con.connect();
 
       int responseCode = con.getResponseCode();
       logger.trace("resonse returned status code {}", responseCode);
       response.setStatus(responseCode);
 
-      copyResponseHeaders(configuration, con, response);
+      if (configuration.isCopyResponseHeaders())
+      {
+        logger.trace("copy response headers");
+        copyResponseHeaders(configuration, con, response);
+      }
+      else
+      {
+        logger.trace("skip copy of response headers");
+      }
 
       copyContent(con, response);