accept-encoding.acceptable_offers is not very useful for the common use case

Open
#387 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
api, backend

Research direction

Start by locating the implementations of acceptable_offers and the deprecated best_match API in the WebOb source, then inspect their tests. Compare behavior for a missing Accept-Encoding header with the examples in this issue; done means the proposed API handles the default identity encoding and preserves offer ordering without the old quality multiplier logic.

Written by the indexing model from the issue text.

Description

While this api is compliant with the RFC at https://tools.ietf.org/html/rfc7231#section-5.3.4, it is not what anybody really expects or wants in the case of a missing header. The answer is pretty much always to use identity when a header is missing. This is what the deprecated best_match api used to do, with best_match(['identity', 'gzip'], default_match='identity').

>>> create_accept_encoding_header(None).acceptable_offers(['identity', 'gzip'])
[('identity', 1.0), ('gzip', 1.0)]
>>> create_accept_encoding_header(None).best_match(['identity', 'gzip'], default_match='identity')
'identity'

The proposed api would be something that implements the following:

offers = ['gzip', 'identity']  # order matters here
default_encoding = 'identity'
if request.accept_encoding:
    encodings = request.accept_encoding.acceptable_offers(offers)
    target_encoding = encodings[0][0] if encodings else default_encoding
else:
    target_encoding = default_encoding

This is very similar to best_match but without any weird server-side quality multiplier logic.

Dominant language
Python
Stars
443
Forks
206
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Pylons/webob

All issues in Pylons/webob

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.