8

I have a Tomcat 7 , Spring 4.2 'RestController' implementation of REST API which seems to produce 'ERR_INVALID_CHUNKED_ENCODING' for few API calls on returning a JSON response.

It is the same code that creates a ResponseEntity. But for few API calls the "Content-Length" is set properly and other calls the "Transfer-Encoding" is set as Chunked.

private CacheControl cacheControl = CacheControl.noStore().mustRevalidate();    

protected <T> ResponseEntity<TNRestResponse<T>> createEntity(TNRestResponse<T> res) {
        return ResponseEntity.ok().cacheControl(cacheControl).body(res);
}

The weird part is the response for the same API call that creates ERR_INVALID_CHUNKED_ENCODING seems to work fine in another environment. The only difference is the client and service is running in the same server in the problematic scenario.

The solution already tried is to set the Content-Length manually which seems to result to premature end of file on the client.The JSON length is only around 468 characters but client receives only 409 characters , even though server logs shows that the full response has been sent and connection is closed.

We are so lost at the solution for this problem because it is the same code acting strangely in different environment.I tried to check the compression settings in server.xml on both the tomcat.But everything looks fine.

Also disabled the proxy setting in both IE and chrome.

Any helpful inputs or insights would be really good ? Thanks in advance.

Oussama Werfelli
  • 513
  • 3
  • 14
Krithika Vittal
  • 1,477
  • 2
  • 16
  • 32
  • https://stackoverflow.com/questions/7503765/how-to-send-the-browser-to-an-error-page-if-part-of-the-response-has-been-sent – Avis Apr 14 '18 at 01:23
  • This error is occurring client side or server side? Also post any exception details if possible – Tarun Lalwani Apr 14 '18 at 06:51
  • @TarunLalwani The error is happening at client side.Error is "'ERR_INVALID_CHUNKED_ENCODING' this in Tools > Developer tools.There are absolutely no errors on thse server logs. – Krithika Vittal Apr 15 '18 at 00:02
  • And what about the network tab? What do you see over there? Please post a screenshot of the same in your question – Tarun Lalwani Apr 15 '18 at 06:16
  • Please refer to this thread https://stackoverflow.com/a/37749537/2453985 and https://stackoverflow.com/a/31453228/2453985 they seems to have already found the solution, also note, you should never change OS level setting or browser setting to fix these types of problem, because they do not work in reality. I hope you should find the solution in the links I provided. – Vikram Palakurthi Apr 19 '18 at 18:36

1 Answers1

1

Follow these steps:

1) Go to your OS's Control panel > internet options > Connections > LAN Settings or to your browser settings.

2) Deselect "Use Proxy" for your LAN or for your browser.

ERR_INVALID_CHUNKED_ENCODING

Original answer

Another original answer

Oleksii Kyslytsyn
  • 2,458
  • 2
  • 27
  • 43