Skip to content

Commit 07c8852

Browse files
spawn-guypre-commit-ci[bot]auvipyNusnus
authored
Feature: urllib3 instead of curl (#2134)
* feature(urllib3): add urllib3 client * test(urllib3): test urllib3 client * test(urllib3): update http test for urllib3 * test(urllib3): use urllib3 client instead of curl * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * style(urllib3): remove unused imports * style(urllib3): fix pre-commit errors * ci(urllib3): remove pycurl dependency * docs(urllib3): add docs * style(urllib3): fix failing gh-workflow py3.8 * style(urllib3): add mention of ProxyManager * style(urllib3): fix pre-commit issues * style(pycurl): remove curl-related code * feat(urllib3): add missing request features (header, auth, ssl, proxy, redirects) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix(urllib3): improve styling * test(urllib3): add new tests * fix(urllib3): fix request auth * fix(aws): validate certificate on request * style(): add missing exports * feat(aws): add ssl certificate verification from boto * feat(urllib): try to use certifi.where() if request.ca_certs are not provided * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * ci(pydocstyle): add missing docstring in public class * test(urllib3): improve test case * ci(pydocstyle): fix multi-line docstring summary should start at the first line * feat(urllib3): remove assert_hostname * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * test(boto): add test for get_cert_path returning .pem file path * test(urllib3): add test for _get_pool_key_parts method * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Asif Saif Uddin <[email protected]> Co-authored-by: Tomer Nosrati <[email protected]>
1 parent 3f5d199 commit 07c8852

File tree

19 files changed

+521
-473
lines changed

19 files changed

+521
-473
lines changed

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ omit =
99
*/python?.?/*
1010
*/site-packages/*
1111
*/pypy/*
12-
*kombu/async/http/curl.py
12+
*kombu/async/http/urllib3_client.py
1313
*kombu/five.py
1414
*kombu/transport/mongodb.py
1515
*kombu/transport/filesystem.py

.github/workflows/linter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
python-version: ["3.12"]
2121
steps:
2222
- name: Install system packages
23-
run: sudo apt-get update && sudo apt-get install libcurl4-openssl-dev libssl-dev
23+
run: sudo apt-get update && sudo apt-get install libssl-dev
2424
- name: Check out code from GitHub
2525
uses: actions/checkout@v4
2626
- name: Set up Python ${{ matrix.python-version }}

.github/workflows/python-package.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
steps:
4040
- name: Install apt packages
4141
if: startsWith(matrix.os, 'blacksmith-4vcpu-ubuntu')
42-
run: sudo apt-get update && sudo apt-get install libcurl4-openssl-dev libssl-dev
42+
run: sudo apt-get update && sudo apt-get install libssl-dev
4343
- uses: actions/checkout@v4
4444
- name: Set up Python ${{ matrix.python-version }}
4545
uses: useblacksmith/setup-python@v6
@@ -98,7 +98,7 @@ jobs:
9898

9999
steps:
100100
- name: Install apt packages
101-
run: sudo apt-get update && sudo apt-get install libcurl4-openssl-dev libssl-dev
101+
run: sudo apt-get update && sudo apt-get install libssl-dev
102102

103103
- uses: actions/checkout@v4
104104
- name: Set up Python ${{ matrix.python-version }}

docs/reference/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Kombu Asynchronous
7171
kombu.asynchronous.debug
7272
kombu.asynchronous.http
7373
kombu.asynchronous.http.base
74-
kombu.asynchronous.http.curl
74+
kombu.asynchronous.http.urllib3_client
7575
kombu.asynchronous.aws
7676
kombu.asynchronous.aws.connection
7777
kombu.asynchronous.aws.sqs
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
============================================================
2+
Urllib3 HTTP Client Pool - ``kombu.asynchronous.http.urllib3_client``
3+
============================================================
4+
5+
.. contents::
6+
:local:
7+
.. currentmodule:: kombu.asynchronous.http.urllib3_client
8+
9+
.. automodule:: kombu.asynchronous.http.urllib3_client
10+
:members:
11+
:undoc-members:

kombu/asynchronous/aws/connection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from vine import promise, transform
99

10-
from kombu.asynchronous.aws.ext import AWSRequest, get_response
10+
from kombu.asynchronous.aws.ext import AWSRequest, get_cert_path, get_response
1111
from kombu.asynchronous.http import Headers, Request, get_client
1212

1313

@@ -92,7 +92,8 @@ def getrequest(self):
9292
headers = Headers(self.headers)
9393
return self.Request(self.path, method=self.method, headers=headers,
9494
body=self.body, connect_timeout=self.timeout,
95-
request_timeout=self.timeout, validate_cert=False)
95+
request_timeout=self.timeout,
96+
validate_cert=True, ca_certs=get_cert_path(True))
9697

9798
def getresponse(self, callback=None):
9899
request = self.getrequest()

kombu/asynchronous/aws/ext.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import boto3
77
from botocore import exceptions
88
from botocore.awsrequest import AWSRequest
9+
from botocore.httpsession import get_cert_path
910
from botocore.response import get_response
1011
except ImportError:
1112
boto3 = None
@@ -19,8 +20,9 @@ class BotoCoreError(Exception):
1920
exceptions.BotoCoreError = BotoCoreError
2021
AWSRequest = _void()
2122
get_response = _void()
23+
get_cert_path = _void()
2224

2325

2426
__all__ = (
25-
'exceptions', 'AWSRequest', 'get_response'
27+
'exceptions', 'AWSRequest', 'get_response', 'get_cert_path',
2628
)

kombu/asynchronous/http/__init__.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING
4-
53
from kombu.asynchronous import get_event_loop
6-
from kombu.asynchronous.http.base import Headers, Request, Response
4+
from kombu.asynchronous.http.base import BaseClient, Headers, Request, Response
75
from kombu.asynchronous.hub import Hub
86

9-
if TYPE_CHECKING:
10-
from kombu.asynchronous.http.curl import CurlClient
11-
12-
__all__ = ('Client', 'Headers', 'Response', 'Request')
7+
__all__ = ('Client', 'Headers', 'Response', 'Request', 'get_client')
138

149

15-
def Client(hub: Hub | None = None, **kwargs: int) -> CurlClient:
10+
def Client(hub: Hub | None = None, **kwargs: int) -> BaseClient:
1611
"""Create new HTTP client."""
17-
from .curl import CurlClient
18-
return CurlClient(hub, **kwargs)
12+
from .urllib3_client import Urllib3Client
13+
return Urllib3Client(hub, **kwargs)
1914

2015

21-
def get_client(hub: Hub | None = None, **kwargs: int) -> CurlClient:
16+
def get_client(hub: Hub | None = None, **kwargs: int) -> BaseClient:
2217
"""Get or create HTTP client bound to the current event loop."""
2318
hub = hub or get_event_loop()
2419
try:

kombu/asynchronous/http/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
if TYPE_CHECKING:
1717
from types import TracebackType
1818

19-
__all__ = ('Headers', 'Response', 'Request')
19+
__all__ = ('Headers', 'Response', 'Request', 'BaseClient')
2020

2121
PYPY = hasattr(sys, 'pypy_version_info')
2222

@@ -236,6 +236,12 @@ def header_parser(keyt=normalize_header):
236236

237237

238238
class BaseClient:
239+
"""Base class for HTTP clients.
240+
241+
This class provides the basic structure and functionality for HTTP clients.
242+
Subclasses should implement specific HTTP client behavior.
243+
"""
244+
239245
Headers = Headers
240246
Request = Request
241247
Response = Response

0 commit comments

Comments
 (0)