title: Serve a file from Python's http.server - correct response with a file
body: <p>I am simply trying to serve a PDF file from the http.server. Here is my code:</p>
  
  <pre><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()
  </code></pre>
  
  <p>I am not sure how I could respond with <code>file.pdf</code> 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. </p>