Skip to content

Commit

Permalink
Update headers logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
EvieePy committed Feb 10, 2024
1 parent 4913e2e commit 06ddd5a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions twitchio/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import logging
import sys
from functools import cached_property
from typing import TYPE_CHECKING, Any

import aiohttp
Expand Down Expand Up @@ -97,12 +98,16 @@ def __init__(self) -> None:
ua = "TwitchioClient (https://github.com/PythonistaGuild/TwitchIO {0}) Python/{1} aiohttp/{2}"
self.user_agent: str = ua.format(__version__, pyver, aiohttp.__version__)

@cached_property
def headers(self) -> dict[str, str]:
return {"User-Agent": self.user_agent}

async def _init_session(self) -> None:
if self.__session and not self.__session.closed:
return

logger.debug("Initialising a new session on %s.", self.__class__.__qualname__)
self.__session = aiohttp.ClientSession()
self.__session = aiohttp.ClientSession(headers=self.headers)

def clear(self) -> None:
if self.__session and self.__session.closed:
Expand All @@ -127,10 +132,6 @@ async def request(
await self._init_session()
assert self.__session is not None

headers_ = kwargs.pop("headers", {})
headers_.setdefault("User-Agent", self.user_agent)
kwargs["headers"] = headers_

route: Route = Route(method, endpoint, use_id=use_id, **kwargs)
logger.debug("Attempting a request to %r with %s.", route, self.__class__.__qualname__)

Expand Down

0 comments on commit 06ddd5a

Please sign in to comment.