forked from SVIG/python-bootcamp
Delete 'httpserver.py'
This commit is contained in:
@@ -1,31 +0,0 @@
|
|||||||
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()
|
|
||||||
Reference in New Issue
Block a user