Skip to content

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

Open
@nulld

Description

@nulld

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions