Skip to content

Disentangle Content-Encoding, Transfer-Encoding, character set conversion and chunked transfers. #14

@mworrell

Description

@mworrell

In Webmachine there is a bit confusion between Content-Encoding and Transfer-Encoding.

The Content-Encoding is applied by functions, though also on the chunks. This doesn't play well with gzip, as that should be applied to the whole entity and not to its chunks.

The idea behind Content-Encoding is that the server has multiple versions of an entity, and can select which version should be served. That means that the server has already a prepared compressed version of the data. The Range is also applied on this (compressed) version of the data.

The Transfer-Encoding is applied after the fetching the correct ranges and can consists of chunking or (further) compression. There can be multiple Transfer-Encodings, they are given in the header in the order that they were applied. For example, first chunking and then gzip will give:

Transfer-Encoding: chunked, gzip

This plays well with different content encodings.

In this way there will be a clear distinction: the controller provides the content and Webzmachine might add transfer encodings.

On a similar note, the character set is almost always UTF-8 and should be supplied by the content, i.e. not changed by Webzmachine.

I propose to add two new callbacks, remove one, and change another:

New:

  • content_encodings_provided/2
  • transfer_encodings_provided/2

Remove:

  • encodings_provided/2

Change return format of:

  • charsets_provided/2

All three will return a list of encodings/charsets, instead of tuples with the encoding and re-code functions.

The content_types_provided/2 function should then take the selected charset and encoding to select the correct content function (or the content function can handle that).

The selected encodings are available from:

  • webmachine_request:get_metadata('content-encoding', ReqData)
  • webmachine_request:get_metadata('chosen-charset', ReqData)
  • webmachine_request:get_metadata('content-type', ReqData)

Metadata

Metadata

Assignees

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