def _setcookie(cls): "Get the CloudFlare cookie and update security." cookie_header = cls.resp.getheader('Set-Cookie') try: cf_cookie = SimpleCookie(cookie_header)[CF_COOKIE] except (CookieError, KeyError): pass # with/out previous cookie else: cf_value = cf_cookie.OutputString('value') cls._headers['Cookie'] = cls._post_headers['Cookie'] = cf_value
def _cfcookie(cls): """Get the CloudFlare cookie and update security. @raise RuntimeWarning: where no CloudFlare cookie""" cookie_header = cls.resp.getheader('Set-Cookie') try: cf_cookie = SimpleCookie(cookie_header)[CF_COOKIE] except (CookieError, KeyError): # warn/failback: use the previous cookie if 'Cookie' not in cls._headers.iterkeys(): warnings.warn("Missing CloudFlare security cookie", category=RuntimeWarning, stacklevel=2) else: cls._post_headers['Cookie'] = \ cls._headers['Cookie'] = cf_cookie.OutputString('value')
def _setcookie(self): """Get the CloudFlare cookie and update security. @raise RuntimeWarning: where no CloudFlare cookie""" #cookie_header = cls.resp.getheader('Set-Cookie') #print 'cookie-header=%s' % cookie_header cookie_header = dict(self.res.info()).get('set-cookie', None) #pprint(cookie_header) try: cf_cookie = SimpleCookie(cookie_header)[CF_COOKIE] #print 'cf_cookie=%s' % cf_cookie except (CookieError, KeyError): # warn/failback: use the previous cookie if 'Cookie' not in self._headers.iterkeys(): warnings.warn("Missing CloudFlare security cookie", category=RuntimeWarning, stacklevel=2) else: self._post_headers['Cookie'] = \ self._headers['Cookie'] = cf_cookie.OutputString('value')