SWI-Prolog HTTP support
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • SWI-Prolog HTTP support
        • Introduction
        • The HTTP client libraries
        • The HTTP server libraries
        • Transfer encodings
          • The library(http/http_chunked) library
        • library(http/websocket): WebSocket support
        • library(http/hub): Manage a hub for websockets
        • Supporting JSON
        • MIME support
        • Security
        • Tips and tricks
        • Status

4 Transfer encodings

The HTTP protocol provides for transfer encodings. These define filters applied to the data described by the Content-type. The two most popular transfer encodings are chunked and deflate. The chunked encoding avoids the need for a Content-length header, sending the data in chunks, each of which is preceded by a length. The deflate encoding provides compression.

Transfer-encodings are supported by filters defined as foreign libraries that realise an encoding/decoding stream on top of another stream. Currently there are two such libraries: library(http/http_chunked.pl) and library(zlib.pl).

There is an emerging hook interface dealing with transfer encodings. The library(http/http_chunked.pl) provides a hook used by library(http/http_open.pl) to support chunked encoding in http_open/3. Note that both http_open.pl and http_chunked.pl must be loaded for http_open/3 to support chunked encoding.

4.1 The library(http/http_chunked) library

http_chunked_open(+RawStream, -DataStream, +Options)
Create a stream to realise HTTP chunked encoding or decoding. The technique is similar to library(zlib), using a Prolog stream as a filter on another stream. See online documentation at http://www.swi-prolog.org/ for details.