|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 | import logging
|
| 3 | +import os |
3 | 4 | import platform
|
| 5 | +from datetime import datetime |
4 | 6 |
|
5 | 7 | import requests
|
6 | 8 | from requests.auth import AuthBase
|
|
20 | 22 | _headers = {'User-Agent': USER_AGENT}
|
21 | 23 |
|
22 | 24 |
|
| 25 | +def __add_auth_headers(headers, auth): |
| 26 | + x_qiniu_date = datetime.utcnow().strftime('%Y%m%dT%H%M%SZ') |
| 27 | + if auth.disable_qiniu_timestamp_signature is not None: |
| 28 | + if not auth.disable_qiniu_timestamp_signature: |
| 29 | + headers['X-Qiniu-Date'] = x_qiniu_date |
| 30 | + elif os.getenv('DISABLE_QINIU_TIMESTAMP_SIGNATURE'): |
| 31 | + if os.getenv('DISABLE_QINIU_TIMESTAMP_SIGNATURE').lower() != 'true': |
| 32 | + headers['X-Qiniu-Date'] = x_qiniu_date |
| 33 | + else: |
| 34 | + headers['X-Qiniu-Date'] = x_qiniu_date |
| 35 | + return headers |
| 36 | + |
| 37 | + |
23 | 38 | def __return_wrapper(resp):
|
24 | 39 | if resp.status_code != 200 or resp.headers.get('X-Reqid') is None:
|
25 | 40 | return None, ResponseInfo(resp)
|
@@ -155,14 +170,18 @@ def _post_with_qiniu_mac(url, data, auth):
|
155 | 170 | qn_auth = qiniu.auth.QiniuMacRequestsAuth(
|
156 | 171 | auth
|
157 | 172 | ) if auth is not None else None
|
158 |
| - return _post(url, data, None, qn_auth) |
| 173 | + headers = __add_auth_headers({}, auth) |
| 174 | + |
| 175 | + return _post(url, data, None, qn_auth, headers=headers) |
159 | 176 |
|
160 | 177 |
|
161 | 178 | def _get_with_qiniu_mac(url, params, auth):
|
162 | 179 | qn_auth = qiniu.auth.QiniuMacRequestsAuth(
|
163 | 180 | auth
|
164 | 181 | ) if auth is not None else None
|
165 |
| - return _get(url, params, qn_auth) |
| 182 | + headers = __add_auth_headers({}, auth) |
| 183 | + |
| 184 | + return _get(url, params, qn_auth, headers=headers) |
166 | 185 |
|
167 | 186 |
|
168 | 187 | def _get_with_qiniu_mac_and_headers(url, params, auth, headers):
|
|
0 commit comments