本文整理汇总了Python中swift.common.swob.Request.headers["Authorization"]方法的典型用法代码示例。如果您正苦于以下问题:Python Request.headers["Authorization"]方法的具体用法?Python Request.headers["Authorization"]怎么用?Python Request.headers["Authorization"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swift.common.swob.Request
的用法示例。
在下文中一共展示了Request.headers["Authorization"]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_request
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import headers["Authorization"] [as 别名]
def handle_request(self, env, start_response):
req = Request(env)
self.logger.debug("Calling S3Multipart Helper Middleware")
# self.logger.debug(req.__dict__)
#
# Check that the request has the correct AA headers
#
if "AWSAccessKeyId" in req.params:
try:
req.headers["Date"] = req.params["Expires"]
req.headers["Authorization"] = "AWS %(AWSAccessKeyId)s:%(Signature)s" % req.params
except KeyError:
return get_err_response("InvalidArgument")(env, start_response)
if "Authorization" not in req.headers:
return self.app(env, start_response)
try:
keyword, info = req.headers["Authorization"].split(" ")
except:
return get_err_response("AccessDenied")(env, start_response)
if keyword != "AWS":
return get_err_response("AccessDenied")(env, start_response)
try:
account, signature = info.rsplit(":", 1)
except:
return get_err_response("InvalidArgument")(env, start_response)
if req.method == "GET":
return self.GET(env, start_response)
elif req.method == "POST":
return self.POST(env, start_response)
elif req.method == "DELETE":
return self.DELETE(env, start_response)
elif req.method != "PUT":
return self.app(env, start_response)
#
# If none of the above, it must be a PUT
#
if "QUERY_STRING" in env:
args = dict(urlparse.parse_qsl(env["QUERY_STRING"], 1))
else:
args = {}
path = None
if "partNumber" in args:
partNo = args["partNumber"]
uploadId = None
if "uploadId" in args:
uploadId = args["uploadId"]
if "QUERY_STRING" in env:
del env["QUERY_STRING"]
if "HTTP_CONTENT_MD5" in env.items():
value = env["HTTP_CONTENT_MD5"]
if value == "":
return get_err_response("InvalidDigest")
try:
env["HTTP_ETAG"] = value.decode("base64").encode("hex")
except:
return get_err_response("InvalidDigest")
if env["HTTP_ETAG"] == "":
return get_err_response("SignatureDoesNotMatch")
#
# If this is part of an S3 multipart upload, then put the parts
# into the proper segment container instead of the primary container
# that was requested. This mimics the SWIFT multipart upload behavior
# and leaves the objects so that they can be accessed by SWIFT or S3
# API calls.
#
path = env["PATH_INFO"]
if path is not None and uploadId is not None and partNo is not None:
version, account, container, obj = split_path(path, 0, 4, True)
env["PATH_INFO"] = "/%s/%s/%s_segments/%s/%s/%d" % (version, account, container, obj, uploadId, int(partNo))
env["RAW_PATH_INFO"] = "/%s_segments/%s/%s/%08d" % (container, obj, uploadId, int(partNo))
return self.app(env, start_response)
示例2: handle_request
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import headers["Authorization"] [as 别名]
def handle_request(self, env, start_response):
req = Request(env)
self.logger.debug("Calling Swift3 Middleware")
# self.logger.debug(req.__dict__)
if "AWSAccessKeyId" in req.params:
try:
req.headers["Date"] = req.params["Expires"]
req.headers["Authorization"] = "AWS %(AWSAccessKeyId)s:%(Signature)s" % req.params
except KeyError:
return get_err_response("InvalidArgument")(env, start_response)
if "Authorization" not in req.headers:
return self.app(env, start_response)
try:
keyword, info = req.headers["Authorization"].split(" ")
except:
return get_err_response("AccessDenied")(env, start_response)
if keyword != "AWS":
return get_err_response("AccessDenied")(env, start_response)
try:
account, signature = info.split(":", 1)
except:
return get_err_response("InvalidArgument")(env, start_response)
try:
controller, path_parts = self.get_controller(env, req.path)
except ValueError:
return get_err_response("InvalidURI")(env, start_response)
# print controller, req.method
if "Date" in req.headers:
date = email.utils.parsedate(req.headers["Date"])
if date is None and "Expires" in req.params:
d = email.utils.formatdate(float(req.params["Expires"]))
date = email.utils.parsedate(d)
if date is None:
return get_err_response("AccessDenied")(env, start_response)
d1 = datetime.datetime(*date[0:6])
d2 = datetime.datetime.utcnow()
epoch = datetime.datetime(1970, 1, 1, 0, 0, 0, 0)
if d1 < epoch:
return get_err_response("AccessDenied")(env, start_response)
delta = datetime.timedelta(seconds=60 * 5)
if d1 - d2 > delta or d2 - d1 > delta:
return get_err_response("RequestTimeTooSkewed")(env, start_response)
token = base64.urlsafe_b64encode(canonical_string(req))
controller = controller(env, self.app, account, token, conf=self.conf, **path_parts)
if hasattr(controller, req.method):
res = getattr(controller, req.method)(env, start_response)
else:
return get_err_response("InvalidURI")(env, start_response)
return res(env, start_response)