Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nulld opened this issue Dec 10, 2020 · 0 comments
Open

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

nulld opened this issue Dec 10, 2020 · 0 comments

Comments

@nulld
Copy link

nulld commented Dec 10, 2020

Found, that haxe.Http 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

My solution to handle this:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant