Fix issues
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Dict
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from client.httpclient import HTTPClient
|
||||
from httplib import parser
|
||||
@@ -21,7 +20,7 @@ def create(method: str, url: str, port):
|
||||
@param port: The port for the command
|
||||
"""
|
||||
|
||||
uri = parser.get_uri(url)
|
||||
uri = parser.uri_from_url(url)
|
||||
if method == "GET":
|
||||
return GetCommand(uri, port)
|
||||
elif method == "HEAD":
|
||||
@@ -125,8 +124,6 @@ class AbstractCommand(ABC):
|
||||
if not sub_request:
|
||||
client.close()
|
||||
|
||||
|
||||
|
||||
def _get_preamble(self, client):
|
||||
"""
|
||||
Returns the preamble (start-line and headers) of the response of this command.
|
||||
@@ -157,28 +154,6 @@ class AbstractCommand(ABC):
|
||||
def _build_message(self, message: str) -> bytes:
|
||||
return (message + "\r\n").encode(FORMAT)
|
||||
|
||||
def parse_uri(self):
|
||||
"""
|
||||
Parses the URI and returns the hostname and path.
|
||||
@return: A tuple of the hostname and path.
|
||||
"""
|
||||
parsed = urlparse(self.uri)
|
||||
|
||||
# If there is no netloc, the url is invalid, so prepend `//` and try again
|
||||
if parsed.netloc == "":
|
||||
parsed = urlparse("http://" + self.uri)
|
||||
|
||||
host = parsed.netloc
|
||||
path = parsed.path
|
||||
if len(path) == 0 or path[0] != '/':
|
||||
path = "/" + path
|
||||
|
||||
port_pos = host.find(":")
|
||||
if port_pos >= 0:
|
||||
host = host[:port_pos]
|
||||
|
||||
return host, path
|
||||
|
||||
|
||||
class HeadCommand(AbstractCommand):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user