# Written by AnActualEmerald
# Last updated 5/20/21
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import urlparse
import time
hostname = "localhost"
serverPort = 8080
def load_bin(file):
with open(file, "rb") as file:
return file.read()
class MemeServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes("<html><head><title>Emerald's Meme Server</title></head>", "utf-8"))
self.wfile.write(bytes("<p>Request: %s</p>" % self.path, "utf-8"))
self.wfile.write(bytes("<body>", "utf-8"))
self.wfile.write(bytes("<p>This will send you memes at some point</p>", "utf-8"))
self.wfile.write(bytes("</body></html>", "utf-8"))
def do_POST(self):
parsed_path = urlparse(self.path)
print(parsed_path.path)
# if parsed_path.path == "/whathow":
# print("Branching to whathow")
self.send_response(200)
self.send_header("Content-type", "video/mp4")
self.end_headers()
self.wfile.write(load_bin("/home/emerald/Pictures/smallcraft.mp4"))
# content_len = int(self.headers.get('Content-Length'))
# post_body = self.rfile.read(content_len)
# print(post_body)
if __name__ == "__main__":
webServer = HTTPServer((hostname, serverPort), MemeServer)
print("Starting server at http://%s:%s" % (hostname, serverPort))
try:
webServer.serve_forever()
except KeyboardInterrupt:
pass
webServer.server_close()
print("Stopped server")