Skip to content

Conversation

@intgr
Copy link
Contributor

@intgr intgr commented Sep 15, 2021

All requests made by python-cas now use a Session object, which enables keep-alive HTTP connections.

The session can also be customized by passing a session= argument to CASClient constructors, to change behaviors such as HTTP headers, proxies, hooks and more.

My use case requires making all CAS requests through an HTTP proxy.

@mingchen
Copy link
Contributor

I see PR status is draft, do you have more changes?

@intgr
Copy link
Contributor Author

intgr commented Sep 15, 2021

Hi! I haven't tested this yet, and haven't checked if something else needs changing.

@intgr intgr force-pushed the allow-customizing-requests-session branch 2 times, most recently from 49b15e9 to 22ebf4b Compare September 16, 2021 09:40
@intgr
Copy link
Contributor Author

intgr commented Sep 16, 2021

@mingchen I tested this together with django-cas-ng/django-cas-ng#298 and it works for my purposes. Does this look good to you?

I'll want to add a test case as well before I consider this ready. Looks like there's nothing in documentation that needs changing?

There are some behavioral differences affecting users of python-cas, since all requests now go through the Session (https://docs.python-requests.org/en/master/user/advanced/#session-objects)

The Session object allows you to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance, and will use urllib3’s connection pooling. So if you’re making several requests to the same host, the underlying TCP connection will be reused, which can result in a significant performance increase (see HTTP persistent connection).

I doubt this causes any breakage for users, but that's famous last words. :)

@mingchen
Copy link
Contributor

Looks good to me. reuse session should not break anything beside improve performance if keep-alive is supported by server.

@intgr intgr force-pushed the allow-customizing-requests-session branch from 22ebf4b to fbf6808 Compare September 17, 2021 10:58
@intgr intgr marked this pull request as ready for review September 17, 2021 10:59
@intgr intgr changed the title Allow customizing requests Session settings Use Session for making requests & allow customization Sep 17, 2021
@intgr intgr force-pushed the allow-customizing-requests-session branch 2 times, most recently from 9b153c8 to 0a93483 Compare September 17, 2021 11:05
@intgr
Copy link
Contributor Author

intgr commented Sep 17, 2021

@mingchen OK, I added a test case and rephrased the PR/commit description. Should be ready now.

All requests made by python-cas now use a Session object, which enables
keep-alive HTTP connections.

The session can also be customized by passing a `session=` argument to
`CASClient` constructors, to change behaviors such as HTTP headers,
proxies, hooks and more.

My use case requires making all CAS requests through an HTTP proxy.
@intgr intgr force-pushed the allow-customizing-requests-session branch from 0a93483 to 8ac88fe Compare September 17, 2021 11:11
@mingchen mingchen merged commit ffd812a into python-cas:master Sep 17, 2021
@mingchen
Copy link
Contributor

Released 1.6.0

@intgr
Copy link
Contributor Author

intgr commented Sep 17, 2021

Awesome! Thanks for responding so quickly and also for your continued maintenance of these projects.

mingchen added a commit to django-cas-ng/django-cas-ng that referenced this pull request Sep 20, 2021
…s Session @intgr

Added a CAS_SESSION_FACTORY setting (must be a callable), which allows customizing many requests behaviors such as HTTP headers, proxies, hooks and more.

An example use case requires making all CAS requests through an HTTP proxy.

This depends upon the python-cas PR at python-cas/python-cas#44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants