File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 36
36
_AES_KEY_SIZE = 32
37
37
_BLOCK_SIZE = 16
38
38
39
+ # Regex constants
40
+ _REGEX_FOR_LOWERCASE_HEADERS = r'(-[a-z])'
41
+
39
42
# Encryption-specific headers
40
43
_HEADER_CLIENT_ENCRYPTION_KEY = 'X-Bunq-Client-Encryption-Key'
41
44
_HEADER_CLIENT_ENCRYPTION_IV = 'X-Bunq-Client-Encryption-Iv'
@@ -260,12 +263,30 @@ def _generate_response_head_bytes(status_code, headers):
260
263
header_tuples = sorted ((k , headers [k ]) for k in headers )
261
264
262
265
for name , value in header_tuples :
266
+ name = _ensure_header_is_correctly_cased (name )
267
+
263
268
if _should_sign_response_header (name ):
264
269
head_string += _FORMAT_HEADER_STRING .format (name , value )
265
270
266
271
return (head_string + _DELIMITER_NEWLINE ).encode ()
267
272
268
273
274
+ def _ensure_header_is_correctly_cased (header_name ):
275
+ """
276
+ :type header_name: str
277
+ :rtype: str
278
+ """
279
+
280
+ header_name = header_name .capitalize ()
281
+
282
+ matches = re .findall (_REGEX_FOR_LOWERCASE_HEADERS , header_name )
283
+
284
+ for match in matches :
285
+ header_name = (re .sub (match , match .upper (), header_name ))
286
+
287
+ return header_name
288
+
289
+
269
290
def _should_sign_response_header (header_name ):
270
291
"""
271
292
:type header_name: str
You can’t perform that action at this time.
0 commit comments