Python HTTP Server gets multiple requests from iPhone
Question: I created a very basic Python http server (Python v3.2) that uses
BaseHTTPRequestHandler to handle GET requests. It works fine when I use any
web browser on a computer. But, when I use a mobile browser on an iPhone, I
always see three GET requests.

For example, if I run this:

    
    
    import http.server
    from http.server import HTTPServer
    from http.server import BaseHTTPRequestHandler
    
    class MyHandler (BaseHTTPRequestHandler):
        def do_GET(self):
            print(self.path)
    
    print('running server on port 80')
    server = HTTPServer(('', 80), MyHandler)
    server.serve_forever()
    

..and then I go to my web browser on my iPhone and enter "192.168.1.191/blah",
the output looks like this:

    
    
    /blah
    /blah
    /blah
    

but if I do it from a computer, it only sends one GET request, so the output
is this:

    
    
    /blah
    

Can anyone explain to me why it behaves this way with the iPhone? It
consistently sends 3 requests every single time. Is there any way around this?

By the way, if I use an Apache server, the iPhone does not behave this way. It
only sends one GET request. It's only when I'm using Python to run a server.

Thanks


Answer: Safari returns a request up to three times - obviously in case of _some_ HTTP
error. Generating a proper HTTP response from inside your do_GET() method will
solve this issue.

