2

I use python's SimpleHTTPServer for tests applications.

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".

Is it possible to change this field? Thx.

1 Answer 1

6

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()

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Is it possible to add this in environment variable or setup in python config file or override in python SimpleHTTPServer module files
yes its possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.