Skip to content

Commit

Permalink
feat(utility): add "verify" attr to "requests.Config"
Browse files Browse the repository at this point in the history
PR Closed: #1271
  • Loading branch information
linjiX committed Feb 10, 2023
1 parent 7ddc500 commit 364b91d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/source/advanced_features/request_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ Note that the default settings can satisfy most use cases.
* - allowed_retry_status
- | The allowed status for retrying request.
| Default: [429, 500, 502, 503, 504]
* - verify
- | Whether to verify the server's TLS certificate.
| Default: True
* - timeout
- | The number of seconds before the request times out.
| Scenario: Enlarge it when under poor network quality.
Expand Down
6 changes: 5 additions & 1 deletion tensorbay/utility/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Config:
allowed_retry_methods: The allowed methods for retrying request.
allowed_retry_status: The allowed status for retrying request.
If both methods and status are fitted, the retrying strategy will work.
verify: Whether to verify the server's TLS certificate.
timeout: Timeout value of the request in seconds.
is_internal: Whether the request is from internal.
Expand All @@ -56,6 +57,7 @@ def __init__(self) -> None:
self.max_retries = 3
self.allowed_retry_methods = ["HEAD", "OPTIONS", "POST", "PUT"]
self.allowed_retry_status = [429, 500, 502, 503, 504]
self.verify = True

self.timeout = 30
self.is_internal = False
Expand Down Expand Up @@ -144,7 +146,9 @@ def request( # type: ignore[override]
"""
try:
response = super().request(method, url, *args, **kwargs)
response = super().request(
method, url, *args, verify=config.verify, **kwargs # type: ignore[misc]
)
if response.status_code not in (200, 201):
logger.error(
"Unexpected status code(%d)!%s", response.status_code, ResponseLogging(response)
Expand Down

0 comments on commit 364b91d

Please sign in to comment.