title: Adding a new field to body of the request from Netflix Zuul Pre-filter
body: <p>I'm trying to add a new field to request's body, in a Zuul Pre-filter.</p>
  
  <p>I'm using one of the Neflix's Zuul sample projects from <a href="https://github.com/spring-cloud-samples/sample-zuul-filters/tree/master/src/main/java/org/springframework/cloud/samplezuulfilters" rel="nofollow noreferrer">here</a>, and my filter's implementation is very similar to <code>UppercaseRequestEntityFilter</code> from this sample.</p>
  
  <p>I was able to apply a transformation such as uppercase, or even to completely modify the request, the only inconvenient is that I'm not able to modify the content of body's request that has a length more than the original length of the body's request.</p>
  
  <p>This is my filter's implementation:</p>
  
  <pre><code>@Component
  public class MyRequestEntityFilter extends ZuulFilter {
      public String filterType() {
          return "pre";
      }
  
      public int filterOrder() {
          return 10;
      }
  
      public boolean shouldFilter() {
          RequestContext context = getCurrentContext();
          return true;
      }
  
      public Object run() {
          try {
              RequestContext context = getCurrentContext();
              InputStream in = (InputStream) context.get("requestEntity");
              if (in == null) {
                  in = context.getRequest().getInputStream();
              }
  
              String body = StreamUtils.copyToString(in, Charset.forName("UTF-8"));
  
              body = body.replaceFirst("qqq", "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq");
  
              // body = body.toUpperCase();
  
              context.set("requestEntity", new ServletInputStreamWrapper(body.getBytes("UTF-8")));
          }
          catch (IOException e) {
              rethrowRuntimeException(e);
          }
          return null;
      }
  } 
  </code></pre>
  
  <p>This is the request that I'm doing:</p>
  
  <p><img src="https://i.stack.imgur.com/LIwZq.png" alt="Request Sample"></p>
  
  <p>This is the response that I'm receiving:</p>
  
  <p><img src="https://i.stack.imgur.com/CggWR.png" alt="Response"></p>