Skip to content
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

Use requests.Session for persistent sessions (HTTP keep-alive) #34

Open
qris opened this issue Dec 5, 2018 · 0 comments
Open

Use requests.Session for persistent sessions (HTTP keep-alive) #34

qris opened this issue Dec 5, 2018 · 0 comments

Comments

@qris
Copy link

qris commented Dec 5, 2018

This can result in a 10x speedup when querying an HTTPS Jenkins server for large numbers of job statuses, by reusing the existing SSL session to avoid renegotiating the key for each request. The code is simple:

class Jenkins(object):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.session = requests.Session()

    def _http_get(self, url, **kwargs):
        ''' Perform an HTTP GET request.

            This will add required authentication and SSL verification arguments.
        '''
        response = self.session.get(url, auth=self.auth, verify=self.verify_ssl_cert, proxies=self.proxies, **kwargs)
        return _validate(response)

    def _http_post(self, url, **kwargs):
        ''' Perform an HTTP POST request.

            This will add required authentication and SSL verification arguments.
        '''
        response = self.session.post(url, auth=self.auth, verify=self.verify_ssl_cert, proxies=self.proxies, **kwargs)
        return _validate(response)
firehooper added a commit to firehooper/autojenkins that referenced this issue Mar 10, 2022
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

No branches or pull requests

1 participant