Skip to content

Commit

Permalink
#279 Cache SSL context in client.py
Browse files Browse the repository at this point in the history
  • Loading branch information
evgkirov committed Feb 1, 2024
1 parent 824c1b6 commit 7090606
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a
Changelog](https://keepachangelog.com/en/1.0.0/), and this project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.0.1](https://github.com/uploadcare/pyuploadcare/compare/v5.0.0...v5.0.1) - unreleased

### Fixed

- The SSL context is now cached by default, resulting in significant performance improvements when initializing the `Uploadcare` class frequently. [#279](https://github.com/uploadcare/pyuploadcare/issues/279)

## [5.0.0](https://github.com/uploadcare/pyuploadcare/compare/v4.3.0...v5.0.0) - 2023-12-28

In version 5.0, we introduce a new [file uploader](https://uploadcare.com/docs/file-uploader/), which is now the default for Django projects. If you prefer to continue using the old jQuery-based widget, you can enable it by setting the `use_legacy_widget` option in your configuration:
Expand Down
16 changes: 14 additions & 2 deletions pyuploadcare/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import socket
import ssl
from time import time
from typing import (
IO,
Expand Down Expand Up @@ -41,6 +42,9 @@
from pyuploadcare.secure_url import BaseSecureUrlBuilder


DEFAULT_SSL_CONTEXT = ssl.create_default_context()


class Uploadcare:
"""Uploadcare client.
Expand Down Expand Up @@ -122,7 +126,11 @@ def __init__(
self.rest_client = Client(
base_url=api_base,
auth=auth,
verify=verify_api_ssl,
verify=(
DEFAULT_SSL_CONTEXT
if verify_api_ssl is True
else verify_api_ssl
),
timeout=timeout,
user_agent_extension=user_agent_extension,
retry_throttled=retry_throttled,
Expand All @@ -131,7 +139,11 @@ def __init__(

self.upload_client = Client(
base_url=upload_base,
verify=verify_upload_ssl,
verify=(
DEFAULT_SSL_CONTEXT
if verify_upload_ssl is True
else verify_upload_ssl
),
timeout=timeout,
user_agent_extension=user_agent_extension,
retry_throttled=retry_throttled,
Expand Down

0 comments on commit 7090606

Please sign in to comment.