MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / HTTPClient

Class HTTPClient

src/core/http_client.py:39–228  ·  view source on GitHub ↗

HTTP 客户端封装 支持代理、重试、错误处理和会话管理

Source from the content-addressed store, hash-verified

37
38
39class HTTPClient:
40 """
41 HTTP 客户端封装
42 支持代理、重试、错误处理和会话管理
43 """
44
45 def __init__(
46 self,
47 proxy_url: Optional[str] = None,
48 config: Optional[RequestConfig] = None,
49 session: Optional[Session] = None
50 ):
51 """
52 初始化 HTTP 客户端
53
54 Args:
55 proxy_url: 代理 URL,如 "http://127.0.0.1:7890"
56 config: 请求配置
57 session: 可重用的会话对象
58 """
59 self.proxy_url = proxy_url
60 self.config = config or RequestConfig()
61 self._session = session
62
63 @property
64 def proxies(self) -> Optional[Dict[str, str]]:
65 """获取代理配置"""
66 if not self.proxy_url:
67 return None
68 return {
69 "http": self.proxy_url,
70 "https": self.proxy_url,
71 }
72
73 @property
74 def session(self) -> Session:
75 """获取会话对象(单例)"""
76 if self._session is None:
77 self._session = Session(
78 proxies=self.proxies,
79 impersonate=self.config.impersonate,
80 verify=self.config.verify_ssl,
81 timeout=self.config.timeout
82 )
83 return self._session
84
85 def request(
86 self,
87 method: str,
88 url: str,
89 **kwargs
90 ) -> Response:
91 """
92 发送 HTTP 请求
93
94 Args:
95 method: HTTP 方法 (GET, POST, PUT, DELETE, etc.)
96 url: 请求 URL

Callers 8

create_http_clientFunction · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected