Skip to content

Commit 72e170d

Browse files
committed
Change protocol if SSL is used.
1 parent 8d253ed commit 72e170d

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

twitchio/web/aio_adapter.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,18 @@ def __init__(
157157
if eventsub_secret and not 10 <= len(eventsub_secret) <= 100:
158158
raise ValueError("Eventsub Secret must be between 10 and 100 characters long.")
159159

160-
self._domain: str | None = None
160+
self._ssl_context: SSLContext | None = ssl_context
161+
self._proto = "https" if (ssl_context or domain) else "http"
162+
161163
if domain:
162164
domain_ = domain.removeprefix("http://").removeprefix("https://").removesuffix("/")
163-
self._domain = f"https://{domain_}"
165+
self._domain = f"{self._proto}://{domain_}"
164166
else:
165-
self._domain = f"http://{self._host}:{self._port}"
167+
self._domain = f"{self._proto}://{self._host}:{self._port}"
166168

167169
path: str = eventsub_path.removeprefix("/").removesuffix("/") if eventsub_path else "callback"
168170
self._eventsub_path: str = f"/{path}"
169171

170-
self._ssl_context: SSLContext | None = ssl_context
171-
172172
self._runner_task: asyncio.Task[None] | None = None
173173
self.startup = self.event_startup
174174
self.shutdown = self.event_shutdown
@@ -197,7 +197,7 @@ def redirect_url(self) -> str:
197197
return f"{self._domain}/oauth/callback"
198198

199199
async def event_startup(self) -> None:
200-
logger.info("Starting %r on http://%s:%s.", self, self._host, self._port)
200+
logger.info("Starting %r on %s://%s:%s.", self, self._proto, self._host, self._port)
201201

202202
async def event_shutdown(self) -> None:
203203
logger.info("Successfully shutdown TwitchIO <%s>.", self.__class__.__qualname__)

twitchio/web/starlette_adapter.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,13 @@ def __init__(
163163
raise ValueError("Eventsub Secret must be between 10 and 100 characters long.")
164164

165165
self._domain: str | None = None
166+
self._proto = "https" if (ssl_keyfile or domain) else "http"
167+
166168
if domain:
167169
domain_ = domain.removeprefix("http://").removeprefix("https://").removesuffix("/")
168-
self._domain = f"https://{domain_}"
170+
self._domain = f"{self._proto}://{domain_}"
169171
else:
170-
self._domain = f"http://{self._host}:{self._port}"
172+
self._domain = f"{self._proto}://{self._host}:{self._port}"
171173

172174
path: str = eventsub_path.removeprefix("/").removesuffix("/") if eventsub_path else "callback"
173175
self._eventsub_path: str = f"/{path}"
@@ -206,7 +208,7 @@ def redirect_url(self) -> str:
206208
return f"{self._domain}/oauth/callback"
207209

208210
async def event_startup(self) -> None:
209-
logger.info("Starting %r on http://%s:%s.", self, self._host, self._port)
211+
logger.info("Starting %r on %s://%s:%s.", self, self._proto, self._host, self._port)
210212

211213
async def event_shutdown(self) -> None:
212214
await self.close()

0 commit comments

Comments
 (0)