-
Notifications
You must be signed in to change notification settings - Fork 363
/
headers.py
57 lines (41 loc) · 1.69 KB
/
headers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
"""
oss2.headers
~~~~~~~~
这个模块包含http请求里header的key定义
同时包含了发送http请求的header, 类型为dict
"""
OSS_USER_METADATA_PREFIX = "x-oss-meta-"
OSS_CANNED_ACL = "x-oss-acl"
IF_UNMODIFIED_SINCE = "If-Unmodified-Since"
IF_MATCH = "If-Match"
OSS_COPY_OBJECT_SOURCE = "x-oss-copy-source"
OSS_COPY_OBJECT_SOURCE_RANGE = "x-oss-copy-source-range"
OSS_REQUEST_ID = "x-oss-request-id"
OSS_SECURITY_TOKEN = "x-oss-security-token"
OSS_NEXT_APPEND_POSITION = "x-oss-next-append-position"
OSS_HASH_CRC64_ECMA = "x-oss-hash-crc64ecma"
OSS_OBJECT_TYPE = "x-oss-object-type"
OSS_OBJECT_ACL = "x-oss-object-acl"
OSS_SYMLINK_TARGET = "x-oss-symlink-target"
OSS_SERVER_SIDE_ENCRYPTION = "x-oss-server-side-encryption"
OSS_SERVER_SIDE_ENCRYPTION_KEY_ID = "x-oss-server-side-encryption-key-id"
OSS_OBJECT_TAGGING = "x-oss-tagging"
OSS_OBJECT_TAGGING_COPY_DIRECTIVE = "x-oss-tagging-directive"
OSS_REQUEST_PAYER = 'x-oss-request-payer'
OSS_TRAFFIC_LIMIT = 'x-oss-traffic-limit'
OSS_TASK_ID = 'x-oss-task-id'
class RequestHeader(dict):
def __init__(self, *arg, **kw):
super(RequestHeader, self).__init__(*arg, **kw)
def set_server_side_encryption(self, algorithm=None, cmk_id=None):
if OSS_SERVER_SIDE_ENCRYPTION in self:
del self[OSS_SERVER_SIDE_ENCRYPTION]
if OSS_SERVER_SIDE_ENCRYPTION_KEY_ID in self:
del self[OSS_SERVER_SIDE_ENCRYPTION_KEY_ID]
if algorithm is "AES256":
self[OSS_SERVER_SIDE_ENCRYPTION] = "AES256"
elif algorithm is "KMS":
self[OSS_SERVER_SIDE_ENCRYPTION] = "KMS"
if cmk_id is not None:
self[OSS_SERVER_SIDE_ENCRYPTION_KEY_ID] = cmk_id