Expose ClientSession defaults such as headers and auth for introspection #3882
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:
headersskip_auto_headersauthjson_serializerequest_classresponse_classws_response_classconnector_ownerraise_for_statustimeoutauto_decompresstrust_envtrace_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.