HaxeFoundation / HaxeFoundation/HaxeManual

add notes about gzip encoded content to haxe.http.HttpBase

Open
#474 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
225
Forks
156
Avg merge
5h 16m
Merged PRs (30d)
1

Description

Found, that [haxe.Http](https://api.haxe.org/haxe/http/HttpBase.html#onData) don't handle `gzip` encoded responses. So, in `onData` callback string is messy if response `Content-Encoding` is `gzip`. IMHO, it have to be mentioned in docs somehow. It can save a lot of time to those who will face this problem.

![image](https://user-images.githubusercontent.com/2820168/101768209-55c0da00-3af6-11eb-96f7-0fcbc832ffe1.png)

My solution to handle this:
```haxe
class Main {
public static function main() {

var r = new haxe.Http("http://cf.gcdn.co/cf/145/assets_remote/assetsRepository.json");
r.onStatus = s -> trace(r.responseHeaders);
r.onBytes = bytes -> {
trace(r.responseHeaders["Content-Encoding"]);
if (r.responseHeaders["Content-Encoding"] == "gzip") {
var reader = new format.gz.Reader(new haxe.io.BytesInput(bytes, 0, bytes.length));
var s = reader.read();
trace(s);
}
};
}
}
```
Btw, we can link cookbok with similair solution to docs.

P.S: it works but only for `sys` . For nodejs target there are no `responseHeaders` property in `haxe.Http` so haven't idea how to handle it.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.