def __init__(self, port, serve_from, max_active_conns=25, default_page='index.html'): """Constructs an HTTP server listening on the specified port and serving files from the specified folder 'serve_from'.""" TCPServer.__init__(self, port, max_active_conns) self.serve_from = serve_from self.default_page = default_page
def handle_tcp(self, pkt): # take care of the usual TCP stuff conn = TCPServer.handle_tcp(self, pkt) if not conn or conn.closed: return conn # check to see if we've received a complete HTTP request url_requested = self.extract_http_get_request(conn) if url_requested: logging.debug('A URL has been requested: ' + url_requested) conn.add_data_to_send(self.__make_response(url_requested, pkt)) logging.debug('The requested URL has been sent; closing the connection') conn.close() return conn
def handle_tcp(self, pkt): # take care of the usual TCP stuff conn = TCPServer.handle_tcp(self, pkt) if not conn or conn.closed: return conn # check to see if we've received a complete HTTP request url_requested = self.extract_http_get_request(conn) if url_requested: logging.debug('A URL has been requested: ' + url_requested) conn.add_data_to_send(self.__make_response(url_requested, pkt)) logging.debug( 'The requested URL has been sent; closing the connection') conn.close() return conn