MCPcopy
hub / github.com/Rapptz/discord.py / HTTPClient

Class HTTPClient

discord/http.py:512–2830  ·  view source on GitHub ↗

Represents an HTTP client sending HTTP requests to the Discord API.

Source from the content-addressed store, hash-verified

510
511
512class HTTPClient:
513 """Represents an HTTP client sending HTTP requests to the Discord API."""
514
515 def __init__(
516 self,
517 loop: asyncio.AbstractEventLoop,
518 connector: Optional[aiohttp.BaseConnector] = None,
519 *,
520 proxy: Optional[str] = None,
521 proxy_auth: Optional[aiohttp.BasicAuth] = None,
522 unsync_clock: bool = True,
523 http_trace: Optional[aiohttp.TraceConfig] = None,
524 max_ratelimit_timeout: Optional[float] = None,
525 ) -> None:
526 self.loop: asyncio.AbstractEventLoop = loop
527 self.connector: aiohttp.BaseConnector = connector or MISSING
528 self.__session: aiohttp.ClientSession = MISSING # filled in static_login
529 # Route key -> Bucket hash
530 self._bucket_hashes: Dict[str, str] = {}
531 # Bucket Hash + Major Parameters -> Rate limit
532 # or
533 # Route key + Major Parameters -> Rate limit
534 # When the key is the latter, it is used for temporary
535 # one shot requests that don't have a bucket hash
536 # When this reaches 256 elements, it will try to evict based off of expiry
537 self._buckets: Dict[str, Ratelimit] = {}
538 self._global_over: asyncio.Event = MISSING
539 self.token: Optional[str] = None
540 self.proxy: Optional[str] = proxy
541 self.proxy_auth: Optional[aiohttp.BasicAuth] = proxy_auth
542 self.http_trace: Optional[aiohttp.TraceConfig] = http_trace
543 self.use_clock: bool = not unsync_clock
544 self.max_ratelimit_timeout: Optional[float] = max(30.0, max_ratelimit_timeout) if max_ratelimit_timeout else None
545
546 user_agent = 'DiscordBot (https://github.com/Rapptz/discord.py {0}) Python/{1[0]}.{1[1]} aiohttp/{2}'
547 self.user_agent: str = user_agent.format(__version__, sys.version_info, aiohttp.__version__)
548
549 def clear(self) -> None:
550 if self.__session and self.__session.closed:
551 self.__session = MISSING
552
553 async def ws_connect(self, url: str, *, compress: int = 0) -> aiohttp.ClientWebSocketResponse:
554 try:
555 timeout: Any = aiohttp.ClientWSTimeout(ws_close=30.0) # pyright: ignore[reportCallIssue]
556 except (AttributeError, TypeError):
557 timeout = 30.0
558
559 kwargs = {
560 'proxy_auth': self.proxy_auth,
561 'proxy': self.proxy,
562 'max_msg_size': 0,
563 'timeout': timeout,
564 'autoclose': False,
565 'headers': {
566 'User-Agent': self.user_agent,
567 },
568 'compress': compress,
569 }

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…