Python SimpleHTTPServer:更改响应头 [英] Python SimpleHTTPServer: change response header
问题描述
我使用python的SimpleHTTPServer来测试应用程序。
I use python's SimpleHTTPServer for tests applications.
现在进行测试我需要在服务器响应头字段Server中进行更改。现在我有Server:SimpleHTTP / 0.6 Python / 2.7.3我想要像Server:Apache123这样的东西。
Now for the test I need to change in the server response header field "Server". Now I have "Server: SimpleHTTP/0.6 Python/2.7.3" I would like something like "Server: Apache123".
是否可以更改此字段? Thx。
Is it possible to change this field? Thx.
推荐答案
如果您想要一些易于编辑的东西,可以使用:
If you wanted to have something easy to edit you could use this:
import SimpleHTTPServer
import BaseHTTPServer
def main():
request_handler = SimpleHTTPServer.SimpleHTTPRequestHandler
request_handler.server_version = "Server: Apache123"
request_handler.sys_version = ""
BaseHTTPServer.test(HandlerClass = request_handler, ServerClass = BaseHTTPServer.HTTPServer)
if __name__ == "__main__":
main()
您可以像运行SimpleHTTPServer一样运行它:
You can run this the same way you run SimpleHTTPServer:
python you_script_name.py port
您也可以编辑它以从命令行中获取所需的名称。
You could also edit it to take the name you want from the command line.
这篇关于Python SimpleHTTPServer:更改响应头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!