Skip to content

Investigate HTTPConnection.auto_open #2775

Description

@sethmlarson

urllib3 makes multiple mentions to a property on http.client.HTTPConnection called auto_open. The property isn't used much in the current stdlib http.client module, but has some implications for urllib3: mainly that connections may not be re-used based on this value?

In urllib3.connection.py:

# Calls self._set_hostport(), so self.host is
# self._tunnel_host below.
self._tunnel()  # type: ignore[attr-defined]
# Mark this connection as not reusable
self.auto_open = 0

In urllib3.connectionpool.py:

conn.close()
if getattr(conn, "auto_open", 1) == 0:
    # This is a proxied connection that has been mutated by
    # http.client._tunnel() and cannot be reused (since it would
    # attempt to bypass the proxy)
    conn = None

I suspect that http.client.HTTPConnection._tunnel() in the past may have rewritten .host and .port properties or something like this and this was our method of "guarding" against that? Currently host and port properties on a connection point to the first origin (read: proxy) on a requests' journey to the destination origin.

  • What is the intent of this property and it's values?
  • Has that intent changed since the original code in urllib3 using the value was written (git blame!)?
  • Can we remove our use/dependence on this value?
  • Should we write some tests for this value? (We currently have none!!! 😱)
  • Can any of these fixes land in 1.26.x?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions