-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathhttp_util.py
More file actions
27 lines (19 loc) · 845 Bytes
/
http_util.py
File metadata and controls
27 lines (19 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Copyright 2026 Canonical Ltd.
# See LICENSE file for licensing details.
"""HTTP client utilities for consistent requests session setup."""
from __future__ import annotations
import requests
def configure_session(adapter: requests.adapters.HTTPAdapter) -> requests.Session:
"""Return a requests session with the provided adapter mounted and proxies disabled.
This standardizes how we create sessions across clients by mounting the same adapter
on both HTTP and HTTPS and ensuring environment proxy variables are ignored.
Args:
adapter: A configured `HTTPAdapter` with retry policy.
Returns:
A configured `requests.Session` instance.
"""
session = requests.Session()
session.mount("http://", adapter)
session.mount("https://", adapter)
session.trust_env = False
return session