Add CRC32 to DynamoDB responses (#3677)

* Add CRC32 to DynamoDB responses

* Change test assertion

* CRC32 - Align Py2/Py3 behaviour

Co-authored-by: Bert Blommers <info@bertblommers.nl>
This commit is contained in:
Jonathan Bergknoff 2021-02-12 08:26:06 -06:00 committed by GitHub
commit 676d61bf5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View file

@ -227,10 +227,14 @@ def gen_amz_crc32(response, headerdict=None):
if not isinstance(response, bytes):
response = response.encode()
crc = str(binascii.crc32(response))
crc = binascii.crc32(response)
if six.PY2:
# https://python.readthedocs.io/en/v2.7.2/library/binascii.html
# TLDR: Use bitshift to match Py3 behaviour
crc = crc & 0xFFFFFFFF
if headerdict is not None and isinstance(headerdict, dict):
headerdict.update({"x-amz-crc32": crc})
headerdict.update({"x-amz-crc32": str(crc)})
return crc