New submission from karl <karl+pythonb...@la-grange.net>: A very simple HTTP server
#!/usr/bin/python3 import http.server from os import chdir # CONFIG ROOTPATH = '/Your/path/' PORT = 8000 # CODE def run(server_class=http.server.HTTPServer, server_handler=http.server.SimpleHTTPRequestHandler): server_address = ('', PORT) httpd = server_class(server_address, server_handler) httpd.serve_forever() class MyRequestHandler(http.server.SimpleHTTPRequestHandler): def do_GET(self): pass if __name__ == '__main__': chdir(ROOTPATH) print("server started on PORT: "+str(PORT)) run(server_handler=MyRequestHandler) Let's start the server. % python3 serveur1.py server started on PORT: 8000 And let's do a GET request with curl. % curl -v http://localhost:8000/ * About to connect() to localhost port 8000 (#0) * Trying ::1... Connection refused * Trying 127.0.0.1... connected * Connected to localhost (127.0.0.1) port 8000 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 > OpenSSL/0.9.8r zlib/1.2.5 > Host: localhost:8000 > Accept: */* > * Empty reply from server * Connection #0 to host localhost left intact curl: (52) Empty reply from server * Closing connection #0 The server sends nothing because GET is not defined and I haven't defined anything in case of errors. So far so good. Now let's do a HEAD request on the same resource. % curl -vsI http://localhost:8000/ * About to connect() to localhost port 8000 (#0) * Trying ::1... Connection refused * Trying 127.0.0.1... connected * Connected to localhost (127.0.0.1) port 8000 (#0) > HEAD / HTTP/1.1 > User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 > OpenSSL/0.9.8r zlib/1.2.5 > Host: localhost:8000 > Accept: */* > * HTTP 1.0, assume close after body < HTTP/1.0 200 OK HTTP/1.0 200 OK < Server: SimpleHTTP/0.6 Python/3.1.2 Server: SimpleHTTP/0.6 Python/3.1.2 < Date: Sun, 30 Oct 2011 14:19:00 GMT Date: Sun, 30 Oct 2011 14:19:00 GMT < Content-type: text/html; charset=utf-8 Content-type: text/html; charset=utf-8 < Content-Length: 346 Content-Length: 346 < * Closing connection #0 The server shows in the log the request localhost - - [30/Oct/2011 10:19:00] "HEAD / HTTP/1.1" 200 - And is answering. I would suggest that the default behavior is to have something similar to the one for the GET aka nothing. Or to modify the library code that for any resources not yet defined. The server answers a code 403 Forbidden. I could submit a patch in the next few days. ---------- components: Library (Lib) messages: 146639 nosy: karlcow, orsenthil priority: normal severity: normal status: open title: http.server - HEAD request when no resource is defined. type: feature request versions: Python 3.1, Python 3.2 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue13294> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com