homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author karlcow
Recipients karlcow, orsenthil
Date 2011年10月30日.14:40:40
SpamBayes Score 8.304149e-05
Marked as misclassified No
Message-id <1319985642.06.0.787750282348.issue13294@psf.upfronthosting.co.za>
In-reply-to
Content
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: 2011年10月30日 14:19:00 GMT
Date: 2011年10月30日 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.
History
Date User Action Args
2011年10月30日 14:40:42karlcowsetrecipients: + karlcow, orsenthil
2011年10月30日 14:40:42karlcowsetmessageid: <1319985642.06.0.787750282348.issue13294@psf.upfronthosting.co.za>
2011年10月30日 14:40:41karlcowlinkissue13294 messages
2011年10月30日 14:40:40karlcowcreate

AltStyle によって変換されたページ (->オリジナル) /