Skip to content

Commit

Permalink
feat: urlのパスを使用しないように close #138
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed May 12, 2024
1 parent 08522a3 commit 051a1f5
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions mipac/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import json
import logging
import re
import sys
from typing import Any, Literal
import urllib.parse

import aiohttp

Expand Down Expand Up @@ -71,18 +71,20 @@ def __init__(self, url: str, token: str | None = None) -> None:
user_agent = (
"Misskey Bot (https://github.com/yupix/MiPA {0})" + "Python/{1[0]}.{1[1]} aiohttp/{2}"
)
self._url: str = url
parsed_url = urllib.parse.urlparse(url)

if parsed_url.scheme not in ["http", "https"] or parsed_url.netloc is None:
raise Exception("Server URL cannot be retrieved or protocol (http / https) is missing")

protocol = True if parsed_url.scheme == "https" else False

self._token: str | None = token
self.user_agent = user_agent.format(__version__, sys.version_info, aiohttp.__version__)
self._session = aiohttp.ClientSession(ws_response_class=MisskeyClientWebSocketResponse)

match_domain = re.search(r"https?:\/\/([^\/]+)", self._url)
match_protocol = re.search(r"^(http|https)", self._url)
if match_domain is None or match_protocol is None:
raise Exception("Server URL cannot be retrieved or protocol (http / https) is missing")
protocol = True if match_protocol.group(1) == "https" else False
self._url = f"{parsed_url.scheme}://{parsed_url.netloc}"
config.from_dict(
host=match_domain.group(1),
host=parsed_url.netloc,
is_ssl=protocol,
)

Expand Down

0 comments on commit 051a1f5

Please sign in to comment.