Skip to content

Expose ClientSession defaults such as headers and auth for introspection #3882

Closed
@mjpieters

Description

Long story short

Too many attributes of ClientSession are private without an explicit need to. The following constructor arguments can never be accessed after creating a session:

  • headers
  • skip_auto_headers
  • auth
  • json_serialize
  • request_class
  • response_class
  • ws_response_class
  • connector_owner
  • raise_for_status
  • timeout
  • auto_decompress
  • trust_env
  • trace_configs

Expected behaviour

I want to be able to create a new session based on an existing session, only tweaking some aspects. Without access to these attributes, you can't properly create a new session instance with only some aspects replaced.

Actual behaviour

You have to access API private attribute to get at this information, making it much harder than necessary to create an updated wrapper as session needs change.

For example, I'm currently implementing an OAuth 2.0 authentication handler, which automatically fetches an authentication token if required for the current request, transparently. We create a client session in a different part of the app, shared between a group of objects, some of which need to dynamically switch to support OAuth 2.0.

Rather than have to create a new session for each of object regardless of OAuth needs (preventing connection re-use between some of these objects where the same server is involved) or having to introspect every request to see if OAuth applies to this specific request, I want to create a new session only when OAuth is actually needed, reusing the same connection pool, if and when OAuth is needed. But this requires knowing the headers, timeouts and trace config on the session used so far.

Metadata

Assignees

No one assigned

    Labels

    HacktoberfestWe think it's good for https://hacktoberfest.digitalocean.com/good first issueGood for newcomerspr-merged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions