I am simply trying to serve a PDF file from the http.server. Here is my code:
from http.server import BaseHTTPRequestHandler, HTTPServer
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'application/pdf')
self.send_header('Content-Disposition', 'attachment; filename="file.pdf"')
self.end_headers()
# not sure about this part below
self.wfile.write(open('/filepath/file.pdf', 'rb'))
myServer = HTTPServer(('localhost', 8080), MyServer)
myServer.serve_forever()
myServer.server_close()
I am not sure how I could respond with file.pdf
now and I am not getting anywhere. I am confident that the headers are correct but I cant manage to send the actual file over.