Esempio n. 1
0
 def _read_initial_client_request(self):
     """
     Reads the client socket and returns the len of bytes received
     """
     try:
         self.http_data = HttpRequest.parse(self._recv_timeout(self.request))
         return len(self.http_data)
     except HttpDataException:
         return 0
Esempio n. 2
0
 def _read_initial_client_request(self):
     """
     Reads the client socket and returns the len of bytes received
     """
     try:
         self.http_data = HttpRequest.parse(self._recv_timeout(self.request))
         return len(self.http_data)
     except HttpDataException:
         return 0
Esempio n. 3
0
    def _forward_remaining_data(self):
        """
        Reads data from the socket list and forwards properly
        """
        timeout = 10
        readable, writable, exceptional = select(self.readable_sockets, [], [], timeout)
        for self.current_socket in readable:
            data = self._recv_timeout(self.current_socket)
            if self.current_socket is self.request:
                # We know is an HTTP Request
                try:
                    self.http_data = HttpRequest.parse(data)
                    # Some clients re-use the socket established with the proxy to send
                    # data to several hosts
                    self.current_destination = self.get_destination_from_data()
                    if not self.http_data.has_keepalive():
                        self.keep_alive = False
                except HttpDataException:
                    #self.readable_sockets.remove(self.request)
                    continue
            else:
                # We know is an HTTP Response or Response data
                try:
                    self.http_data = HttpResponse.parse(data)
                except HttpDataException:
                    # It could be something else like a chunked response or who knows xD
                    if len(data) > 0:
                        # In this particular case, send data directly
                        self.send_data(socket_to=self.request, data=data)
                    else:
                        self.readable_sockets.remove(self.current_destination.socket_connection)
                        self.destination_list.remove(self.current_destination)
                        self.keep_alive = False
                    continue

            self.send_data(socket_to=self.__get_peer_socket(), data=repr(self.http_data))
Esempio n. 4
0
    def _forward_remaining_data(self):
        """
        Reads data from the socket list and forwards properly
        """
        timeout = 10
        readable, writable, exceptional = select(self.readable_sockets, [], [], timeout)
        for self.current_socket in readable:
            data = self._recv_timeout(self.current_socket)
            if self.current_socket is self.request:
                # We know is an HTTP Request
                try:
                    self.http_data = HttpRequest.parse(data)
                    # Some clients re-use the socket established with the proxy to send
                    # data to several hosts
                    self.current_destination = self.get_destination_from_data()
                    if not self.http_data.has_keepalive():
                        self.keep_alive = False
                except HttpDataException:
                    #self.readable_sockets.remove(self.request)
                    continue
            else:
                # We know is an HTTP Response or Response data
                try:
                    self.http_data = HttpResponse.parse(data)
                except HttpDataException:
                    # It could be something else like a chunked response or who knows xD
                    if len(data) > 0:
                        # In this particular case, send data directly
                        self.send_data(socket_to=self.request, data=data)
                    else:
                        self.readable_sockets.remove(self.current_destination.socket_connection)
                        self.destination_list.remove(self.current_destination)
                        self.keep_alive = False
                    continue

            self.send_data(socket_to=self.__get_peer_socket(), data=repr(self.http_data))