Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Chunk must be last transfer encoding 502 error code

Dears,

I hope you are doing well,

I am facing an issue with one of the target systems that uses Spring Boot as a backend.

{
    "fault": {
        "faultstring": "chunked MUST be the last transfer-coding applied to the message-body",
        "detail": {
            "errorcode": "protocol.http.ChunkedShouldBeLast"
        }
    }
}

I sent the request from Postman through APIgee to the target

502 Bad Gateway
The server, working as a gateway got an invalid response.

But If I take the cURL command and send it to the target from the "RMP" server directly I get a successful response.

 

Also, I detected some headers from the backend server,  Transfer-Encoding: chunked

Is this header causing the issue?

Could you please support me?

Thank you

Amer Hijazi

 

Solved Solved
0 7 844
1 ACCEPTED SOLUTION

Apigee seems to be complaining that your upstream system  (the thing implemented in Spring Boot) is sending back an invalid or incorrect response. 

You didn't note the entire response, but provided an observation about exactly ONE header, Transfer-Encoding.  Is it possible that the response is also using a header Content-Encoding: chunked ?  If that is the case then Apigee is rightly complaining. The error is expected.

If this is what's happening, to correct the problem, Check the backend system, and make sure the headers it returns in the response are valid and correct. Content-Encoding can take values like gzip, deflate, compress, and some others. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding   It should never contain the word "chunked". 

A response with "chunked" in the Transfer-Encoding header is ok, and valid. Apigee should not complain about that.  If the response uses both Transfer-Encoding:chunked and Content-Encoding:chunked, the latter header is wrong.  It should not be there. 

 

 

View solution in original post

7 REPLIES 7