(self, rcvd_bytes)
Processes the response from the proxy. If the tunnel is successfully
        created, notifies the client that we are ready to send requests. If not
        raises a TunnelError.
Processes the response from the proxy. If the tunnel is successfully
        created, notifies the client that we are ready to send requests. If not
        raises a TunnelError.
Processes the response from the proxy . If the tunnel is successfully created notifies the client that we are ready to send requests . If not raises a TunnelError .
def processProxyResponse(self, rcvd_bytes):
        """Processes the response from the proxy. If the tunnel is successfully
        created, notifies the client that we are ready to send requests. If not
        raises a TunnelError.
        """
        self._connectBuffer += rcvd_bytes
        # make sure that enough (all) bytes are consumed
        # and that we've got all HTTP headers (ending with a blank line)
        # from the proxy so that we don't send those bytes to the TLS layer
        #
        # see https://github.com/scrapy/scrapy/issues/2491
        if b'\r\n\r\n' not in self._connectBuffer:
            return
        self._protocol.dataReceived = self._protocolDataReceived
        respm = TunnelingTCP4ClientEndpoint._responseMatcher.match(self._connectBuffer)
        if respm and int(respm.group('status')) == 200:
            # set proper Server Name Indication extension
            sslOptions = self._contextFactory.creatorForNetloc(self._tunneledHost, self._tunneledPort)
            self._protocol.transport.startTLS(sslOptions, self._protocolFactory)
            self._tunnelReadyDeferred.callback(self._protocol)
        else:
            if respm:
                extra = {'status': int(respm.group('status')),
                         'reason': respm.group('reason').strip()}
            else:
                extra = rcvd_bytes[:self._truncatedLength]
            self._tunnelReadyDeferred.errback(
                TunnelError('Could not open CONNECT tunnel with proxy '
                            f'{self._host}:{self._port} [{extra!r}]')
            )
def processProxyResponse ( self , rcvd_bytes ) : self . _connectBuffer += rcvd_bytes # make sure that enough (all) bytes are consumed # and that we've got all HTTP headers (ending with a blank line) # from the proxy so that we don't send those bytes to the TLS layer # # see https://github.com/scrapy/scrapy/issues/2491 if b'\r\n\r\n' not in self . _connectBuffer : return self . _protocol . dataReceived = self . _protocolDataReceived respm = TunnelingTCP4ClientEndpoint . _responseMatcher . match ( self . _connectBuffer ) if respm and int ( respm . group ( 'status' ) ) == 200 : # set proper Server Name Indication extension sslOptions = self . _contextFactory . creatorForNetloc ( self . _tunneledHost , self . _tunneledPort ) self . _protocol . transport . startTLS ( sslOptions , self . _protocolFactory ) self . _tunnelReadyDeferred . callback ( self . _protocol ) else : if respm : extra = { 'status' : int ( respm . group ( 'status' ) ) , 'reason' : respm . group ( 'reason' ) . strip ( ) } else : extra = rcvd_bytes [ : self . _truncatedLength ] self . _tunnelReadyDeferred . errback ( TunnelError ( 'Could not open CONNECT tunnel with proxy ' f'{self._host}:{self._port} [{extra!r}]' ) )