FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

http.server does not accept "absolute-form" as "request-target" · Issue #132741 · python/cpython · GitHub

Repository navigation

http.server does not accept "absolute-form" as "request-target" #132741

Open

Description

Bug report

Bug description:

python3 -m http.server &
printf "GET http://127.0.0.1:8000/ HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n" | nc 127.0.0.1 8000

Expected: 200 OK
Got: 404 File not found

Reference:

[RFC 9112] (Section 3.2)
[RFC 7230] (Section 5.3)
[RFC 2616] (Section 5.1.2)

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Activity

  1. donbarbos commented on Apr 20, 2025

    Contributor

    it seems this is expected behavior, since if the request ends with a backslash, a 404 error is returned:

    cpython/Lib/http/server.py

    Lines 771 to 778 in 5d8e432

    # check for trailing "/" which should return 404. See Issue17324
    # The test for this was added in test_httpserver.py
    # However, some OS platforms accept a trailingSlash as a filename
    # See discussion on python-dev and Issue34711 regarding
    # parsing and rejection of filenames with a trailing slash
    if path.endswith("/"):
    self.send_error(HTTPStatus.NOT_FOUND, "File not found")
    return None

    this was discussed here: #78892

  2. donbarbos commented on Apr 20, 2025

    Contributor

    you can use next command:

    printf "GET / HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n" | nc 127.0.0.1 8000
  3. GreenYun commented on Apr 20, 2025

    Author

    it seems this is expected behavior, since if the request ends with a backslash, a 404 error is returned:

    This is not expected. A "request-target" with trailing backslash is for listing the contents for a real directory.

    you can use next command:

    printf "GET / HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n" | nc 127.0.0.1 8000

    Yes, this is correct.

    However, the question was found since, according to the RFCs, a forward HTTP proxy may forward the "request-target" to the origin server. This leads the real client to get an error when accessing via an HTTP proxy.

  4. donbarbos commented on Apr 20, 2025

    Contributor

    I understand you, and I'd be happy to fix this behavior if core developer agrees.

    But I think it's worth noting that "absolute-form" is typically used when making a request through an HTTP proxy, and http.server isn't a proxy - it's a basic file-serving web server.

    cc @picnixz

  5. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Apr 20, 2025
  6. GreenYun commented on Apr 24, 2025

    Author

    and http.server isn't a proxy - it's a basic file-serving web server.

    When I found this problem, I was using http.server as the origin server behind a proxy server, and I got 404 because the proxy server forwarded the "absolute-form".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL