Skip to content

Parsing error occurs when POST response is empty gzip content type #349

@sthamman

Description

@sthamman

Describe the bug
Parsing error occurs when POST response is empty gzip content type

To Reproduce

Server

response.setContentType("application/json; charset=utf-8");
response.setHeader("Content-Encoding", "gzip");
response.setStatus(HttpServletResponse.SC_ACCEPTED);
response.getWriter().write(new char[0]); // optional

Client

Unirest.post("http://localhost:8080")
  .asObject(Map.class)
  .getParsingError()
  .get();

Stack Trace

kong.unirest.UnirestParsingException: kong.unirest.UnirestException: java.io.EOFException
	at kong.unirest.BaseResponse.setParsingException(BaseResponse.java:93)
	at kong.unirest.BasicResponse.<init>(BasicResponse.java:48)
	at kong.unirest.apache.BaseApacheClient.transformBody(BaseApacheClient.java:56)
	at kong.unirest.apache.ApacheClient.request(ApacheClient.java:127)
	at kong.unirest.BaseRequest.asObject(BaseRequest.java:249)
	at io.cloudio.scale.kafka.rest.FlowrestTest.main(FlowrestTest.java:33)
Caused by: kong.unirest.UnirestException: java.io.EOFException
	at kong.unirest.apache.ApacheResponse.getContentAsBytes(ApacheResponse.java:89)
	at kong.unirest.apache.ApacheResponse.getContentAsString(ApacheResponse.java:107)
	at kong.unirest.apache.ApacheResponse.getContentAsString(ApacheResponse.java:97)
	at kong.unirest.ObjectResponse.readBody(ObjectResponse.java:57)
	at kong.unirest.ObjectResponse.<init>(ObjectResponse.java:40)
	at kong.unirest.BaseRequest.lambda$asObject$3(BaseRequest.java:249)
	at kong.unirest.apache.BaseApacheClient.transformBody(BaseApacheClient.java:53)
	... 3 more
Caused by: java.io.EOFException
	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:268)
	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:258)
	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:164)
	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:79)
	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:91)
	at kong.unirest.apache.ApacheResponse.getContentAsBytes(ApacheResponse.java:85)
	... 9 more

Expected behavior
Parsing error should not occur

Environmental Data:

  • Java Version: 1.8
  • Version: 3.7.01

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions