python / python/cpython

Error calling BaseHTTPRequestHandler.end_headers()

Open
#131,715 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

If a call is made to BaseHTTPRequestHandler.end_headers() but no headers or response have been queued, an exception is raised exposing implementation details.

    class request_handler(BaseHTTPRequestHandler):
        def do_GET(self):
            self.end_headers()

Actual result

AttributeError("'request_handler' object has no attribute '_headers_buffer'")

Expected result:

pass

flush_headers has a guard to check if the buffer has been allocated which is missing from end_headers

if hasattr(self, '_headers_buffer'):
CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-131718

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 by locating CPython's BaseHTTPRequestHandler.end_headers() and compare its handling with flush_headers(), especially the _headers_buffer guard described in the report. Done means calling end_headers() without queued headers or a response completes without exposing an AttributeError; check linked PR gh-131718 before starting.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.