title: Request header too large while sending image in REST response
body: <p>I have a REST service developed using Spring Boot that is attempting to send back image data to the client, which would then be displayed in the browser. However when i attempt this, i get the following error:</p>
  
  <pre><code>2016-09-26 08:40:31.897  INFO 6435 --- [nio-8080-exec-7] o.a.coyote.http11.Http11NioProcessor     : Error parsing HTTP request header
   Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
  
  java.lang.IllegalArgumentException: Request header is too large
      at org.apache.coyote.http11.InternalNioInputBuffer.fill(InternalNioInputBuffer.java:111) ~[tomcat-embed-core-8.0.36.jar!/:8.0.36]
      at org.apache.coyote.http11.AbstractNioInputBuffer.parseRequestLine(AbstractNioInputBuffer.java:267) ~[tomcat-embed-core-8.0.36.jar!/:8.0.36]
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1013) ~[tomcat-embed-core-8.0.36.jar!/:8.0.36]
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670) [tomcat-embed-core-8.0.36.jar!/:8.0.36]
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520) [tomcat-embed-core-8.0.36.jar!/:8.0.36]
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476) [tomcat-embed-core-8.0.36.jar!/:8.0.36]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_60]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_60]
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.36.jar!/:8.0.36]
      at java.lang.Thread.run(Unknown Source) [na:1.8.0_60]
  </code></pre>
  
  <p>My service code is as follows:</p>
  
  <pre><code>    @RequestMapping(method = RequestMethod.POST, value = "/com")
          public String handleCompare(@RequestParam("testid") String test,
                                      RedirectAttributes redirectAttributes, Model model) throws IOException {
  
          File f=new File("Sampletest.jpg");
          BufferedImage origImg=ImageIO.read(f);
          ByteArrayOutputStream baos=new ByteArrayOutputStream();
          ImageIO.write(origImg, "jpg", baos );
          byte[] imageInByte=baos.toByteArray();
          byte[] encoded= Base64.encodeBase64(imageInByte);
          String encodedString = new String(encoded);
          model.addAttribute("webcamattr", encodedString);
          return "resp";
        }
  </code></pre>
  
  <p>The relevant part of "resp.html" is as follows:</p>
  
  <pre><code>   &lt;table&gt;
              &lt;tr&gt;
                  &lt;td align="center"&gt;&lt;b&gt;Response Image&lt;/b&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr th:each="webfile : ${webcamattr}"&gt;
                  &lt;td&gt; &lt;img width="300" height="300" src="data:image/jpeg;base64" th:src="${webcamattr}"&gt;&lt;/img&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
  </code></pre>
  
  <p>My application.properties file is as follows:</p>
  
  <pre><code>multipart.maxFileSize=10Mb
  multipart.maxRequestSize=10Mb
  </code></pre>
  
  <p>The file that I'm trying to send is just 19KB in size but I'm not sure why it is throwing a large request header error. Could you please help in identifying what am I doing wrong? Is the image data being passed in the request header? If so, how can i send it in the response body?</p>
  
  <p>Thanks</p>