Logo Search packages:      
Sourcecode: tcpwatch-httpproxy version File versions  Download package

def tcpwatch::HTTPProxyToClientConnection::openProxyConnection (   self,
  request 
)

Parses the client connection and opens a connection to an
HTTP server.

Definition at line 1162 of file tcpwatch.py.

01162                                           :
        """Parses the client connection and opens a connection to an
        HTTP server.
        """
        first_line = request.first_line.strip()
        if not ' ' in first_line:
            raise ValueError, ('Malformed request: %s' % first_line)
        command, url = first_line.split(' ', 1)
        pos = url.rfind(' HTTP/')
        if pos >= 0:
            protocol = url[pos + 1:]
            url = url[:pos].rstrip()
        else:
            protocol = 'HTTP/1.0'
        if url.startswith('http://'):
            # Standard proxy
            urlpart = url[7:]
            if '/' in urlpart:
                host, path = url[7:].split('/', 1)
                path = '/' + path
            else:
                host = urlpart
                path = '/'
        else:
            # Transparent proxy
            host = request.headers.get('HOST')
            path = url
        if not host:
            raise ValueError, ('Request type not supported: %s' % url)

        if ':' in host:
            host, port = host.split(':')
            port = int(port)
        else:
            port = 80

        if '@' in host:
            username, host = host.split('@')

        obs = self._obs
        if obs is not None:
            eo = EndpointObserver(obs, 0)
            ptos = HTTPProxyToServerConnection(self, (eo,))
        else:
            ptos = HTTPProxyToServerConnection(self)

        self._response_order.append(ptos)

        ptos.write('%s %s %s\r\n' % (command, path, protocol))
        # Duplicate the headers sent by the client.
        if request.header:
            ptos.write(request.header)
        else:
            ptos.write('\r\n')
        if request.body_data:
            ptos.write(''.join(request.body_data))
        ptos.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        ptos.connect((host, port))

    def close(self):


Generated by  Doxygen 1.6.0   Back to index