update client
This commit is contained in:
42
client/ResponseHandler.py
Normal file
42
client/ResponseHandler.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import os
|
||||
from socket import socket
|
||||
from typing import Dict
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
class ResponseHandler:
|
||||
client: socket
|
||||
url: str
|
||||
headers: Dict[str, str]
|
||||
|
||||
def __init__(self, url: str, client: socket):
|
||||
self.headers = {}
|
||||
self.url = url
|
||||
self.client = client
|
||||
pass
|
||||
|
||||
def get_html_filename(self):
|
||||
filename = "index.html"
|
||||
|
||||
parsed = urlparse(self.url)
|
||||
if parsed.netloc == "":
|
||||
parsed = urlparse("//" + self.url)
|
||||
if len(parsed.path) != 0:
|
||||
index = parsed.path.rfind("/")
|
||||
if index == -1:
|
||||
filename = parsed.path
|
||||
elif parsed.path[-1] != "/":
|
||||
filename = parsed.path[index:]
|
||||
|
||||
result = os.path.basename(filename).strip()
|
||||
return result
|
||||
|
||||
|
||||
class PlainResponseHandler(ResponseHandler):
|
||||
def __init__(self, url: str, client: socket):
|
||||
super().__init__(url, client)
|
||||
|
||||
|
||||
class ChunkedResponseHandler(ResponseHandler):
|
||||
def __init__(self, url: str, client: socket):
|
||||
super().__init__(url, client)
|
Reference in New Issue
Block a user