title: SimpleHTTPServer Custom Headers
body: <p>By default SimpleHTTPServer sends it's own headers.</p>
  <p>I've been trying to figure out how to send my own headers and found <a href="https://gist.github.com/daimatz/3ca32ae11d9635372853" rel="nofollow noreferrer">this solution</a>. I tried adapting it to my (very) simple proxy:</p>
  <pre><code>import SocketServer
  import SimpleHTTPServer
  import urllib
  
  class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
    headers = ['Date: Wed, 29 Oct 2014 15:54:43 GMT', 'Server: Apache', 'Accept-Ranges: bytes', 'X-Mod-Pagespeed: 1.6.29.7-3566', 'Vary: Accept-Encoding', 'Cache-Control: max-age=0, no-cache', 'Content-Length: 204', 'Connection: close', 'Content-Type: text/html']
  
    def end_headers(self):
      print &quot;Setting custom headers&quot;
      self.custom_headers()
  
      SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self)
  
    def custom_headers(self):
      for i in self.headers:
        key, value = i.split(&quot;:&quot;, 1)
        self.send_header(key, value)
  
    def do_GET(self):
        self.copyfile(urllib.urlopen(self.path), self.wfile)
  
  httpd = SocketServer.ForkingTCPServer(('', PORT), Proxy)
  httpd.serve_forever()
  </code></pre>
  <p>But <code>end_headers()</code> doesn't set the custom headers (confirmed on Wireshark).</p>
  <p>Given a list of <code>headers</code> like the one in my little snippet, how I can overwrite <code>SimpleHTTPServer's</code> default headers and server my own?</p>