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 3636_AES_KEY_SIZE = 32
3737_BLOCK_SIZE = 16
3838
39+ # Regex constants
40+ _REGEX_FOR_LOWERCASE_HEADERS = r'(-[a-z])'
41+
3942# Encryption-specific headers
4043_HEADER_CLIENT_ENCRYPTION_KEY = 'X-Bunq-Client-Encryption-Key'
4144_HEADER_CLIENT_ENCRYPTION_IV = 'X-Bunq-Client-Encryption-Iv'
@@ -260,12 +263,30 @@ def _generate_response_head_bytes(status_code, headers):
260263 header_tuples = sorted ((k , headers [k ]) for k in headers )
261264
262265 for name , value in header_tuples :
266+ name = _ensure_header_is_correctly_cased (name )
267+
263268 if _should_sign_response_header (name ):
264269 head_string += _FORMAT_HEADER_STRING .format (name , value )
265270
266271 return (head_string + _DELIMITER_NEWLINE ).encode ()
267272
268273
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+
269290def _should_sign_response_header (header_name ):
270291 """
271292 :type header_name: str
You can’t perform that action at this time.
0 commit comments