Search code examples
actionscript-3httpsocketschunking

Decoding chunked HTTP with Actionscript


I have successfully connected to an HTTP server with ActionScript 3 over sockets. The only problem is, the server is sending chunked HTTP. Is there a generic function in any other language I can look at that clearly shows how to decode the chunking? I'm pretty sure there are no ActionScript libraries around for this.


Solution

  • The HTTP 1.1 specification (or from W3C) provides a pseudocode example of how to decode chunked transfer-coding:

    length := 0
    read chunk-size, chunk-extension (if any) and CRLF
    while (chunk-size > 0) {
       read chunk-data and CRLF
       append chunk-data to entity-body
       length := length + chunk-size
       read chunk-size and CRLF
    }
    read entity-header
    while (entity-header not empty) {
       append entity-header to existing header fields
       read entity-header
    }
    Content-Length := length
    Remove "chunked" from Transfer-Encoding