question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Decoding errror with content-encoding 'gzip'

See original GitHub issue

Describe the bug

When trying to fetch an organization from public GitHub via getOrganization("...") the response body cannot be parsed correctly and the method throws an IOException.

There seems to be an issue with whitespaces in the (assumed) JSON response, indicated by Illegal character ((CTRL-CHAR, code 31)). Some debugging down to GithubResponse::parseBody shows that

responseInfo.headerField("content-encoding")

resolves to "gzip" for some reason.

Here is the full stacktrace:

org.kohsuke.github.HttpException: Server returned HTTP response code: 200, message: 'null' for URL: https://api.github.com/orgs/MovingBlocks
	at org.kohsuke.github.GitHubClient.interpretApiError(GitHubClient.java:443) ~[github-api-1.108.jar:na]
	at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:366) ~[github-api-1.108.jar:na]
	at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:310) ~[github-api-1.108.jar:na]
	at org.kohsuke.github.Requester.fetch(Requester.java:71) ~[github-api-1.108.jar:na]
	at org.kohsuke.github.GitHub.getOrganization(GitHub.java:489) ~[github-api-1.108.jar:na]
	at org.terasology.launcher.updater.LauncherUpdater.updateAvailable(LauncherUpdater.java:91) ~[main/:na]
	at org.terasology.launcher.LauncherInitTask.checkForLauncherUpdates(LauncherInitTask.java:181) [main/:na]
	at org.terasology.launcher.LauncherInitTask.call(LauncherInitTask.java:81) [main/:na]
	at org.terasology.launcher.LauncherInitTask.call(LauncherInitTask.java:44) [main/:na]
	at javafx.concurrent.Task$TaskCallable.call(Task.java:1423) [jfxrt.jar:na]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_232]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_232]
Caused by: com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens
 at [Source: (String)"      ??Mo?0??????n?5?C??????P?b?6??EC.???}?7;e7??C?z_?s?G?y?????]a~?<??Io??:???>?v????{?z??T?^??+?????;"?Q?X9??$E#?G?*?-s?C4G^\e?A?^??D?A?]M????jz????????H^C???????p\|P??gJ???L??V8a.??6?d?L????>?l?[??
??l?=?
?|???L&?pV?D?j,?K??j?v?6??Sc??O?W*?=g?8Y?_??n(?fHL??fBQj!i.F^?#K	4S?P?�?-?p?|??Y?8??????9?T?"??]q??/?
x?J?Yn???v????_????pP???/?(ZD?"???$?$??5??S?????!?Mnn?M????q?6???XP?  "; line: 1, column: 2]
	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1840) ~[jackson-core-2.10.2.jar:2.10.2]
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:712) ~[jackson-core-2.10.2.jar:2.10.2]
	at com.fasterxml.jackson.core.base.ParserMinimalBase._throwInvalidSpace(ParserMinimalBase.java:690) ~[jackson-core-2.10.2.jar:2.10.2]
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipWSOrEnd(ReaderBasedJsonParser.java:2373) ~[jackson-core-2.10.2.jar:2.10.2]
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:672) ~[jackson-core-2.10.2.jar:2.10.2]
	at com.fasterxml.jackson.databind.ObjectReader._initForReading(ObjectReader.java:357) ~[jackson-databind-2.10.2.jar:2.10.2]
	at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1704) ~[jackson-databind-2.10.2.jar:2.10.2]
	at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1261) ~[jackson-databind-2.10.2.jar:2.10.2]
	at org.kohsuke.github.GitHubResponse.parseBody(GitHubResponse.java:84) ~[github-api-1.108.jar:na]
	at org.kohsuke.github.Requester.lambda$fetch$1(Requester.java:71) ~[github-api-1.108.jar:na]
	at org.kohsuke.github.GitHubClient.createResponse(GitHubClient.java:404) ~[github-api-1.108.jar:na]
	at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:358) ~[github-api-1.108.jar:na]
	... 10 common frames omitted

To Reproduce

This is the MWE from my code to reproduce this error.

try {
	Github github = GitHub.connectAnonymously();
	GHOrganization movingBlocks = github.getOrganization("MovingBlocks");
} catch (IOException e) {
	e.printStacktrace();
}

Expected behavior

I expect that a response with 200 OK is parsed correctly and does not throw an IOException.

Alternatively, is there a way to set custom headers, e.g., setting “accept-encoding” to ensure the lib can parse the response body?

Desktop (please complete the following information):

  • OS: macOS / Windows 10
  • Java: 1.8.0_232 BellSoft
  • Version 1.108

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
tomakehurstcommented, Mar 30, 2020

Switching the implementation of GitHubResponse.headerField() to this seems to fix the problem:

public String headerField(String name) {
    return headers.entrySet()
        .stream()
        .filter(entry -> name.equalsIgnoreCase(entry.getKey()))
        .findFirst()
        .map(entry -> entry.getValue().get(0))
        .orElse(null);
}

I’ll raise a PR, but I’m struggling to create a test case at the moment because (the ironies) I can’t persuade WireMock not to capitalise the content-encoding header name.

2reactions
tomakehurstcommented, Mar 30, 2020

OK, found the problem: headerField is case-sensitive and GitHub have changed their response headers to be all lower case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Content decoding has failed" error when download files using ...
1 Answer 1 ... Try: Response.Headers.Remove("Content-Encoding"); Response.AppendHeader("Content-Encoding", "gzip");. Another problem may be the ...
Read more >
Accept-Encoding, Content-Encoding, and ERR CONTENT ...
An error message in a browser-based app lead to some digging and learning about content encoding and negotiation.
Read more >
“Content decoding has failed” error when download files using ...
My web app generates a CSV file on the fly, but whenever I use GZIP compression, the download fails: HTTP/1.1 200 OK Cache-Control:...
Read more >
Content-Encoding - HTTP - MDN Web Docs
The Content-Encoding representation header lists any encodings that have been applied to the representation (message payload), and in what ...
Read more >
Received response with content-encoding: gzip, but ... - GitHub
This seems like the server is returning data it claims is gzipped, but isn't, or is invalid somehow. curl agrees with this assessment, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found