Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1618

Show
Ignore:
Timestamp:
02/16/07 13:21:12
Author:
fumanchu
Message:

Fix for #654 (More gracefull failure and traceback when client tries non-SSL connection to SSL server).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/wsgiserver/__init__.py

    r1616 r1618  
    478478        buf.append("\r\n") 
    479479        self.sendall("".join(buf)) 
     480 
     481 
     482class NoSSLError(Exception): 
     483    """Exception raised when a client speaks HTTP to an HTTPS socket.""" 
     484    pass 
    480485 
    481486 
     
    509514                if is_reader and e.args == (-1, 'Unexpected EOF'): 
    510515                    return "" 
    511                 if is_reader and e.args[0][0][2] == 'ssl handshake failure': 
     516                 
     517                thirdarg = None 
     518                try: 
     519                    thirdarg = e.args[0][0][2] 
     520                except IndexError: 
     521                    pass 
     522                 
     523                if is_reader and thirdarg == 'ssl handshake failure': 
    512524                    return "" 
     525                if thirdarg == 'http request': 
     526                    # The client is talking HTTP to an HTTPS server. 
     527                    raise NoSSLError() 
    513528                raise 
    514529            if time.time() - start > self.ssl_timeout: 
     
    619634        except (KeyboardInterrupt, SystemExit): 
    620635            raise 
     636        except NoSSLError: 
     637            # Unwrap our sendall 
     638            req.sendall = self.socket._sock.sendall 
     639            req.simple_response("400 Bad Request", 
     640                                "The client sent a plain HTTP request, but " 
     641                                "this server only speaks HTTPS on this port.") 
    621642        except: 
    622643            if req: 

Hosted by WebFaction

Log in as guest/cpguest to create tickets