Command add properties for fields
This commit is contained in:
@@ -38,18 +38,38 @@ class AbstractCommand(ABC):
|
||||
"""
|
||||
A class representing the command for sending an HTTP request.
|
||||
"""
|
||||
uri: str
|
||||
host: str
|
||||
path: str
|
||||
port: int
|
||||
_uri: str
|
||||
_host: str
|
||||
_path: str
|
||||
_port: int
|
||||
sub_request: bool
|
||||
|
||||
def __init__(self, uri: str, port):
|
||||
self.uri = uri
|
||||
self.host, _, self.path = parser.parse_uri(uri)
|
||||
self.port = int(port)
|
||||
self._port = int(port)
|
||||
self.sub_request = False
|
||||
|
||||
@property
|
||||
def uri(self):
|
||||
return self._uri
|
||||
|
||||
@uri.setter
|
||||
def uri(self, value):
|
||||
self._uri = value
|
||||
self._host, self._port, self._path = parser.parse_uri(value)
|
||||
|
||||
@property
|
||||
def host(self):
|
||||
return self._host
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def port(self):
|
||||
return self._port
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def method(self):
|
||||
@@ -61,6 +81,7 @@ class AbstractCommand(ABC):
|
||||
|
||||
@param sub_request: If this execution is in function of a prior command.
|
||||
"""
|
||||
self.uri = ""
|
||||
self.sub_request = sub_request
|
||||
(host, path) = self.parse_uri()
|
||||
|
||||
|
@@ -78,7 +78,7 @@ class BasicResponseHandler(ResponseHandler):
|
||||
if self.msg.status == 101:
|
||||
# Switching protocols is not supported
|
||||
print("".join(self.msg.raw), end="")
|
||||
return
|
||||
return None
|
||||
|
||||
if 200 <= self.msg.status < 300:
|
||||
return self.retriever
|
||||
@@ -87,6 +87,7 @@ class BasicResponseHandler(ResponseHandler):
|
||||
# Redirect
|
||||
self._skip_body()
|
||||
return self._handle_redirect()
|
||||
|
||||
if 400 <= self.msg.status < 600:
|
||||
self._skip_body()
|
||||
# Dump headers and exit with error
|
||||
@@ -114,7 +115,6 @@ class BasicResponseHandler(ResponseHandler):
|
||||
raise InvalidResponse("Only http is supported")
|
||||
|
||||
self.cmd.uri = location
|
||||
self.cmd.host, self.cmd.port, self.cmd.path = parser.parse_uri(location)
|
||||
|
||||
if self.msg.status == 301:
|
||||
logging.info("Status 301. Closing socket [%s]", self.cmd.host)
|
||||
@@ -177,8 +177,8 @@ class DownloadHandler(ResponseHandler, ABC):
|
||||
|
||||
class RawDownloadHandler(DownloadHandler):
|
||||
|
||||
def __init__(self, retriever: Retriever, client: HTTPClient, msg: Message, cmd: AbstractCommand, dir=None):
|
||||
super().__init__(retriever, client, msg, cmd, dir)
|
||||
def __init__(self, retriever: Retriever, client: HTTPClient, msg: Message, cmd: AbstractCommand, directory=None):
|
||||
super().__init__(retriever, client, msg, cmd, directory)
|
||||
|
||||
def handle(self) -> str:
|
||||
logging.debug("Retrieving payload")
|
||||
|
Reference in New Issue
Block a user