tornadoweb / tornadoweb/tornado

HTTPHeaders.get_list() improve functionality

Open
#1,094 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

httpserver
Dominant language
Python
Stars
22.2k
Forks
5.6k
Avg merge
3h 42m
Merged PRs (30d)
16

Description

Currently if in the headers the Accept header had a value of
text/*, text/html, text/html;level=1, */*,
then
self.request.headers.get_list("Accept")
would return:
["text/*, text/html, text/html;level=1, */*"]

The documentation for get_list says:
"Returns all values for the given header as a list."

When I originally read this I thought the multiple accept types would be broken up and all added to a list such as:
["text/*", "text/html", "text/html;level=1", "*/*"]

I think that this would be much more useful and make more sense, or at least it would be in the project I'm working on.

I achieved the same effect by the following code:

response_type = self.request.headers.get_list("Accept")
response_type = [item.strip() for index in range(len(response_type)) for item in response_type[index].split(",")]

Also it would be helpful if the documentation was explicit about what's returned if the header name wasn't given.

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.

Research direction

Start at HTTPHeaders.get_list() and trace how comma-separated header values are currently returned. Check the existing documentation for get_list, then define and verify the behavior for multiple Accept values and for a missing header name, including appropriate tests if the surrounding code provides them.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.