Skip to content

Commit b2f851e

Browse files
authored
Merge pull request #57 from bunq/feature/make_sure_headers_are_correctly_cased_bunq/sdk_python#51
Feature/make sure headers are correctly cased bunq/sdk python#51
2 parents d288c92 + 5112ded commit b2f851e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,4 @@ config.json
9292
connectQr.png
9393
.DS_Store
9494
bunq_sdk.egg-info
95+
.idea/codeStyles/

bunq/sdk/security.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
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 = _get_header_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 _get_header_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+
269290
def _should_sign_response_header(header_name):
270291
"""
271292
:type header_name: str

0 commit comments

Comments
 (0)