Skip to content

Commit

Permalink
Fix content extraction from part (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
razorx89 authored Oct 30, 2020
1 parent 78dce0b commit e8c14db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/dicomweb_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,9 @@ def _extract_part_content(cls, part: bytes) -> Union[bytes, None]:
"""
if part in (b'', b'--', b'\r\n') or part.startswith(b'--\r\n'):
return None
if b'\r\n\r\n' in part:
return part.split(b'\r\n\r\n')[1]
idx = part.index(b'\r\n\r\n')
if idx > -1:
return part[idx + 4:]
raise ValueError('Message part does not contain CRLF CRLF')

def _decode_multipart_message(
Expand Down
6 changes: 6 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
)


def test_content_extraction_from_part():
part = b'xyz\r\n\r\n\x00\x01\x00\x02\x0d\x0a\x0d\x0a\x00\x01\x00\x02'
content = DICOMwebClient._extract_part_content(part)
assert len(content) == 12


def _chunk_message(message: bytes, chunk_size: int) -> bytes:
chunked_message = b''
for i in range(0, len(message), chunk_size):
Expand Down

0 comments on commit e8c14db

Please sign in to comment.