Added HTTP performance test

This commit is contained in:
cheezedoodle2
2023-04-12 21:39:39 -07:00
parent 568e890c9f
commit b1fccaf628
121 changed files with 177 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
import os
from http.server import SimpleHTTPRequestHandler, HTTPServer
from urllib.parse import urlparse
class JPEGRequestHandler(SimpleHTTPRequestHandler):
def do_GET(self):
url = urlparse(self.path)
path = url.path
if path.endswith('.jpg'):
file_path = path[1:]
if os.path.isfile(file_path):
self.send_response(200)
self.send_header('Content-Type', 'image/jpeg')
self.end_headers()
with open(file_path, 'rb') as file:
self.wfile.write(file.read())
else:
self.send_error(404, 'File not found')
else:
self.send_error(403, 'Only .jpg files are allowed')
def run(server_class=HTTPServer, handler_class=JPEGRequestHandler, port=8000):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print(f'Serving JPEGs on port {port}...')
httpd.serve_forever()
if __name__ == '__main__':
run()