本文整理汇总了Python中swift.common.swob.Request.environ['REMOTE_USER']方法的典型用法代码示例。如果您正苦于以下问题:Python Request.environ['REMOTE_USER']方法的具体用法?Python Request.environ['REMOTE_USER']怎么用?Python Request.environ['REMOTE_USER']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swift.common.swob.Request
的用法示例。
在下文中一共展示了Request.environ['REMOTE_USER']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import environ['REMOTE_USER'] [as 别名]
def __call__(self, env, start_response):
req = Request(env)
token = extract_from_cookie_to_header(req,
self.cookie_key,
('x-auth-token', 'x-storage-token'))
if token:
account_id, _junk = \
self.storage_driver(env, self.prefix).get_id(token)
if account_id:
req.environ['REMOTE_USER'] = account_id
def cookie_resp(status, response_headers, exc_info=None):
resp_headers = HeaderKeyDict(response_headers)
if 'x-auth-token' in resp_headers:
auth_token = resp_headers['x-auth-token']
expires_in = int(resp_headers.get('x-auth-token-expires', 0))
storage_url = resp_headers.get('x-storage-url', '')
path_parts = urlparse(storage_url)
domain = path_parts.netloc
secure = False
if path_parts.scheme == 'https':
secure = True
if auth_token and domain:
new_cookie = create_auth_cookie('session',
domain,
token=auth_token,
expires_in=expires_in,
secure=secure,
httponly=True)
response_headers.append(('Set-Cookie', new_cookie))
new_cookie = create_auth_cookie('storage',
domain,
token=storage_url,
expires_in=expires_in,
secure=secure)
response_headers.append(('Set-Cookie', new_cookie))
return start_response(status, response_headers, exc_info)
return self.app(env, cookie_resp)