def _update_cookies(self, response): cookies = Cookie() # Load any generated cookies. for cookie in response.headers.getall('Set-Cookie'): cookies.load(cookie) self.cookies.update({i.name.decode('ascii'): i.value.decode('ascii') for i in cookies.values()})
def _handle_cookies(self, resp): existing = resp.headers.getall("Set-Cookie") if not existing: return dict() cookies = Cookie() for header in existing: cookies.load(header) for key in cookies: self._cookies[key] = cookies[key].value
def get_cookie(response, key): existing = response.headers.getall("Set-Cookie") if not existing: return False cookies = Cookie() for header in existing: cookies.load(header) if isinstance(key, text_type): key = key.encode("utf8") if key in cookies: return cookies[key] return None
def unset_cookie(self, key, strict=True): """ Unset a cookie with the given name (remove it from the response). """ existing = self.headers.getall('Set-Cookie') if not existing and not strict: return cookies = Cookie() for header in existing: cookies.load(header) if key in cookies: del cookies[key] del self.headers['Set-Cookie'] for m in list(cookies.values()): self.headerlist.append(('Set-Cookie', str(m))) elif strict: raise KeyError("No cookie has been set with the name %r" % key)
def unset_cookie(self, key, strict=True): """ Unset a cookie with the given name (remove it from the response). """ existing = self.headers.getall('Set-Cookie') if not existing and not strict: return cookies = Cookie() for header in existing: cookies.load(header) if key in cookies: del cookies[key] del self.headers['Set-Cookie'] for m in cookies.values(): self.headerlist.append(('Set-Cookie', str(m))) elif strict: raise KeyError("No cookie has been set with the name %r" % key)
def unset_cookie(self, name, strict=True): """ Unset a cookie with the given name (remove it from the response). """ existing = self.headers.getall('Set-Cookie') if not existing and not strict: return cookies = Cookie() for header in existing: cookies.load(header) if isinstance(name, text_type): name = name.encode('utf8') if name in cookies: del cookies[name] del self.headers['Set-Cookie'] for m in cookies.values(): self.headerlist.append(('Set-Cookie', m.serialize())) elif strict: raise KeyError("No cookie has been set with the name %r" % name)
def normalize_cookie_tween(request): if request.path in ignore or request.path.startswith("/static/"): return handler(request) session = request.session if session or session._cookie_name not in request.cookies: return handler(request) response = handler(request) existing = response.headers.getall("Set-Cookie") if existing: cookies = Cookie() for header in existing: cookies.load(header) if session._cookie_name in cookies: return response response.delete_cookie(session._cookie_name, path=session._cookie_path, domain=session._cookie_domain) return response
def unset_cookie(self, key, strict=True): """ Unset a cookie with the given name (remove it from the response). """ existing = self.headers.getall("Set-Cookie") if not existing and not strict: return cookies = Cookie() for header in existing: cookies.load(header) if isinstance(key, text_type): key = key.encode("utf8") if key in cookies: del cookies[key] del self.headers["Set-Cookie"] for m in cookies.values(): self.headerlist.append(("Set-Cookie", m.serialize())) elif strict: raise KeyError("No cookie has been set with the name %r" % key)
def normalize_cookie_tween(request): if request.path in ignore or request.path.startswith('/static/'): return handler(request) session = request.session if session or session._cookie_name not in request.cookies: return handler(request) response = handler(request) existing = response.headers.getall('Set-Cookie') if existing: cookies = Cookie() for header in existing: cookies.load(header) if session._cookie_name in cookies: return response response.delete_cookie( session._cookie_name, path=session._cookie_path, domain=session._cookie_domain, ) return response