title: ServiceStack Proxy Feature code optimization
body: <p>I'm tasked with creating a proxy for an internal system. The proxy needs to add a Basic authentication header to each request as well as log it and the response.</p>
  <p>I'm using ServiceStack's Proxy Feature plugin, but feel like the code is repetitive, as I do the following for each operation:</p>
  <pre class="lang-cs prettyprint-override"><code>Plugins.Add(new ProxyFeature(matchingRequests: req =&gt; req.PathInfo.ToLower().StartsWith(&quot;/opretaftale&quot;), resolveUrl: req =&gt; gensamOpretaftaleUrl)
  {
      ProxyRequestFilter = (req, httpWebRequest) =&gt;
      {
          try
          {
              httpWebRequest.AddBasicAuth(clientId, clientPassword);
          }
          catch (System.Exception ex)
          {
              Log.Error(ex, &quot;...&quot;);
          }
      },
  
      TransformRequest = async (res, requestStream) =&gt;
      {
          using (var reader = new StreamReader(requestStream, Encoding.UTF8))
          {
              var requestBody = await reader.ReadToEndAsync();
              Log.Information(&quot;request: &quot; + requestBody);
              return MemoryStreamFactory.GetStream(requestBody.ToUtf8Bytes());
          }
      },
  
      TransformResponse = async (res, responseStream) =&gt;
      {
          using (var reader = new StreamReader(responseStream, Encoding.UTF8))
          {
              var responseBody = await reader.ReadToEndAsync();
              Log.Information(&quot;response: &quot; + responseBody);
              return MemoryStreamFactory.GetStream(responseBody.ToUtf8Bytes());
          }
      }
  });
  </code></pre>
  <p>Is it possible to have the same actions for multiple requests and do I really need the TransformRequest/TransformResponse to log the request/response? I'm having difficulty getting the stream content from the ProxyRequestFilter/ProxyResponseFilter actions...</p>
  <p>Thanks!</p>