Skip to content

added support in requests.Session #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

uriyay
Copy link

@uriyay uriyay commented Mar 21, 2024

What kind of change does this PR introduce?

Added support in requests.Session in order to solve #54

What is the current behavior?

client.execute() calls to requests.post(), using a session object is not available.

What is the new behavior?

client.execute() gets a new parameter named session that holds a Session object that will be used for making the POST request.
The new parameter is None by default, if its None a new session is created and will be used for making the POST request.

Does this PR introduce a breaking change?

No, you can still skip passing session parameter and the code will act the same as before.

Other information

This feature allows users to:

  1. Log in with a complex flow such as oidc, that sets an authorization cookies for the session
  2. Prevent requests from using .netrc file by default, by setting session.trust_env to False:
    Don't override Authorization header when contents are bearer token (or any other token) psf/requests#3929

@xkludge
Copy link
Contributor

xkludge commented Mar 21, 2024

@uriyay thanks for the contribution, however this change as you can see breaks tests on the existing functionality.

We should potentially introduce checking if session is the instance of Session. If it is not then we perform the default requests.post.

If session is the instance of Session then we can produce a session.post.

Note please include tests to cover these scenarios.

…n. added tests for testing client.execute() with a given session object
Copy link
Contributor

@xkludge xkludge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. I left some feedback on the changes.

**kwargs: Any,
):
"""Make synchronous request to graphQL server."""
request_body = self.__request_body(
query=query, variables=variables, operation_name=operation_name
)

result = requests.post(
post_method = requests.post
if session:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should validate the type that session is a Session to prevent injection.

Suggested change
if session:
if isinstance(session, Session):

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