title: How to add Request Headers in filter and get that header in controller
body: <p>I am Using following wrapper to add headers its adding headers in request </p>
  
  <pre><code>final class MutableHttpServletRequest extends HttpServletRequestWrapper {
      // holds custom header and value mapping
      private final Map&lt;String, String&gt; customHeaders;
  
      public MutableHttpServletRequest(HttpServletRequest request){
          super(request);
          this.customHeaders = new HashMap&lt;String, String&gt;();
      }
  
      public void putHeader(String name, String value){
          this.customHeaders.put(name, value);
      }
  
      public String getHeader(String name) {
          // check the custom headers first
          String headerValue = customHeaders.get(name);
  
          if (headerValue != null){
              return headerValue;
          }
          // else return from into the original wrapped object
          return ((HttpServletRequest) getRequest()).getHeader(name);
      }
  
      public Enumeration&lt;String&gt; getHeaderNames() {
          // create a set of the custom header names
          Set&lt;String&gt; set = new HashSet&lt;String&gt;(customHeaders.keySet());
  
          // now add the headers from the wrapped request object
          @SuppressWarnings("unchecked")
          Enumeration&lt;String&gt; e = ((HttpServletRequest) getRequest()).getHeaderNames();
          while (e.hasMoreElements()) {
              // add the names of the request headers into the list
              String n = e.nextElement();
              set.add(n);
          }
  
          // create an enumeration from the set and return
          return Collections.enumeration(set);
      }
  }
  </code></pre>
  
  <p>with filter </p>
  
  <pre><code>@Override
  public void doFilter(ServletRequest request, ServletResponse response,
          FilterChain chain) throws IOException, ServletException {
      HttpServletRequest req = (HttpServletRequest) request;
      MutableHttpServletRequest mutableRequest = new MutableHttpServletRequest(req);
      ...
      mutableRequest.putHeader("x-user-id", "1");
      chain.doFilter(mutableRequest, response);
  }
  </code></pre>
  
  <p>but i cant able to get that header in contoller its giving null
  so anyone please tell me how to set headers in filter and access that header in controller.</p>
  
  <pre><code> @GetMapping("/api1/temp1")
          private ResponseEntity&lt;Object&gt;  temp1(@RequestHeader HttpHeaders headers, @RequestHeader(value="x-user-id",required=false) String userId){
              System.out.println(userId));
              return new ResponseEntity&lt;Object&gt;("temp1 method", HttpStatus.OK);
          }
  </code></pre>