Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Small refactor of AWS Signer classes for both sync and async clients ([866](https://github.com/opensearch-project/opensearch-py/pull/866))
- Small refactor to fix overwriting the module files when generating apis ([874](https://github.com/opensearch-project/opensearch-py/pull/874))
- Fixed a "type ignore" lint error
- Added support for explicit proxy to RequestsHttpConnection ([908](https://github.com/opensearch-project/opensearch-py/pull/908))
### Deprecated
### Removed
### Fixed
Expand Down
6 changes: 5 additions & 1 deletion opensearchpy/connection/http_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import time
import warnings
from typing import Any, Collection, Mapping, Optional, Union
from typing import Any, Collection, Mapping, MutableMapping, Optional, Union

try:
import requests
Expand Down Expand Up @@ -74,6 +74,7 @@ class RequestsHttpConnection(Connection):
:arg metrics: metrics is an instance of a subclass of the
:class:`~opensearchpy.Metrics` class, used for collecting
and reporting metrics related to the client's operations;
:arg proxies: optional dictionary mapping protocol to the URL of the proxy.
"""

def __init__(
Expand All @@ -92,6 +93,7 @@ def __init__(
opaque_id: Any = None,
pool_maxsize: Any = None,
metrics: Metrics = MetricsNone(),
proxies: Optional[MutableMapping[str, str]] = None,
**kwargs: Any,
) -> None:
self.metrics = metrics
Expand Down Expand Up @@ -132,6 +134,8 @@ def __init__(
http_auth = tuple(http_auth.split(":", 1)) # type: ignore
self.session.auth = http_auth

self.session.proxies = proxies or {}

self.base_url = f"{self.host}{self.url_prefix}"
self.session.verify = verify_certs
if not client_key:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ def test_http_auth_list(self) -> None:
con = RequestsHttpConnection(http_auth=["username", "secret"])
self.assertEqual(("username", "secret"), con.session.auth)

def test_proxies(self) -> None:
con = RequestsHttpConnection(proxies={"http": "http://localhost:8118"})
self.assertEqual({"http": "http://localhost:8118"}, con.session.proxies)

def test_repr(self) -> None:
con = self._get_mock_connection({"host": "opensearchpy.com", "port": 443})
self.assertEqual(
Expand Down
Loading