0
기본적으로 SimpleHTTPServer는 자신의 헤더를 보냅니다.SimpleHTTPServer 사용자 정의 헤더
나는 내 머리글을 보내는 방법을 알아 내려고 노력해 왔으며 this solution을 찾았습니다. 나는 나의 (매우) 간단한 프록시에 적응 시도 :
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 "Setting custom headers"
self.custom_headers()
SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self)
def custom_headers(self):
for i in self.headers:
key, value = i.split(":", 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()
그러나 end_headers()
가 (와이어 샤크에서 확인) 사용자 정의 헤더를 설정하지 않습니다.
headers
이 내 작은 스 니펫에있는 것과 같습니다. 어떻게하면 SimpleHTTPServer's
기본 헤더와 서버를 덮어 쓸 수 있습니까?
[가능한 복제본] (http://stackoverflow.com/questions/22308786/python-simplehttpserver-change-response-header/22309792#22309792)? – Noelkd