Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error calling BaseHTTPRequestHandler.end_headers() #131715

Open
jnewbigin opened this issue Mar 25, 2025 · 0 comments
Open

Error calling BaseHTTPRequestHandler.end_headers() #131715

jnewbigin opened this issue Mar 25, 2025 · 0 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@jnewbigin
Copy link

jnewbigin commented Mar 25, 2025

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

@jnewbigin jnewbigin added the type-bug An unexpected behavior, bug, or error label Mar 25, 2025
jnewbigin added a commit to jnewbigin/cpython that referenced this issue Mar 25, 2025
end_headers was missing a check to verify that the `_headers_buffer`
had been allocated and there was indeed any headers to send.
@ZeroIntensity ZeroIntensity added the stdlib Python modules in the Lib dir label Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants