Пример #1
0
    def _handle_request(self, connection_hash, tcp_pkt):

        if http.has_complete_headers(tcp_pkt.data):
            req = http.parse_request(tcp_pkt.data)

            logging.debug('Request URL: %s' % req['host'] + req['path'])

        logging.debug('Storing stream %s.' % connection_hash)
        self.packet_streams[connection_hash] = TcpStream(connection_hash)
Пример #2
0
    def _handle_request(self, connection_hash, tcp_pkt):

        if http.has_complete_headers(tcp_pkt.data):
            req = http.parse_request(tcp_pkt.data)

            logging.debug('Request URL: %s' % req['host'] + req['path'])

        logging.debug('Storing stream %s.' % connection_hash)
        self.packet_streams[connection_hash] = TcpStream(connection_hash)
Пример #3
0
    def _append_packet(self, packet):
        """Appends a packet to the end of the list of received packets and processes it"""
        self.next_seq += len(packet.data)

        if self.headers is not None:
            if self.packets is None:
                self.packets = StringIO.StringIO()
            self.packets.write(packet.data)
            self.http_bytes_loaded += len(packet.data)
        else:
            self.header_data += packet.data

        # check if we have enough packets for the entire http header
        if self.is_http and self.headers is None:
            if http.has_complete_headers(self.header_data):
                resp = http.parse_response(self.header_data)
                self.header_data = None
                if self.packets is None:
                    self.packets = StringIO.StringIO()
                self.packets.write(resp['body'])
                self.headers = resp['headers']
                self.http_bytes_loaded = len(resp['body'])

                self._on_http_headers()

        # check if we have finished the request
        if self.http_content_length is not None:

            if self.http_content_length == self.http_bytes_loaded:
                self.is_finished = True
            elif self.http_content_length < self.http_bytes_loaded:
                logging.error(
                    "Received data was longer than the content length header")
                self.is_valid = False
                self.is_finished = True

        self._handle_ordered_packet(packet)
Пример #4
0
    def _append_packet(self, packet):
        """Appends a packet to the end of the list of received packets and processes it"""
        self.next_seq += len(packet.data)

        if self.headers is not None:
            if self.packets is None:
                self.packets = StringIO.StringIO()
            self.packets.write(packet.data)
            self.http_bytes_loaded += len(packet.data)
        else:
            self.header_data += packet.data

        # check if we have enough packets for the entire http header
        if self.is_http and self.headers is None:
            if http.has_complete_headers(self.header_data):
                resp = http.parse_response(self.header_data)
                self.header_data = None
                if self.packets is None:
                    self.packets = StringIO.StringIO()
                self.packets.write(resp['body'])
                self.headers = resp['headers']
                self.http_bytes_loaded = len(resp['body'])

                self._on_http_headers()

        # check if we have finished the request
        if self.http_content_length is not None:

            if self.http_content_length == self.http_bytes_loaded:
                self.is_finished = True
            elif self.http_content_length < self.http_bytes_loaded:
                logging.error("Received data was longer than the content length header")
                self.is_valid = False
                self.is_finished = True

        self._handle_ordered_packet(packet)