Skip to content

Commit

Permalink
Remove boundary from multipart/related accept header
Browse files Browse the repository at this point in the history
  • Loading branch information
hackermd committed Sep 14, 2018
1 parent 8730eb4 commit ed7c13b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/dicomweb_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '0.9.0'
__version__ = '0.9.1'

from dicomweb_client.api import DICOMwebClient
24 changes: 7 additions & 17 deletions src/dicomweb_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
import email
import six
from urllib3.filepost import choose_boundary
from io import BytesIO
from collections import OrderedDict
if sys.version_info.major < 3:
Expand Down Expand Up @@ -400,9 +399,9 @@ def _http_get(self, url, params, headers):
'''
url += self._build_query_string(params)
logger.debug('GET: {}'.format(url))
resp = self._session.get(url=url, headers=headers)
resp.raise_for_status()
return resp
response = self._session.get(url=url, headers=headers)
response.raise_for_status()
return response

def _http_get_application_json(self, url, **params):
'''Performs a HTTP GET request that accepts "applicaton/dicom+json"
Expand Down Expand Up @@ -532,10 +531,7 @@ def _http_get_multipart_application_dicom(self, url, **params):
DICOM data sets
'''
content_type = (
'multipart/related; type="application/dicom"; '
'boundary="--{boundary}"'.format(boundary=choose_boundary())
)
content_type = 'multipart/related; type="application/dicom"'
resp = self._http_get(url, params, {'Accept': content_type})
datasets = self._decode_multipart_message(resp.content, resp.headers)
return [pydicom.dcmread(BytesIO(ds)) for ds in datasets]
Expand All @@ -557,10 +553,7 @@ def _http_get_multipart_application_octet_stream(self, url, **params):
content of HTTP message body parts
'''
content_type = (
'multipart/related; type="application/octet-stream"; '
'boundary="--{boundary}"'.format(boundary=choose_boundary())
)
content_type = 'multipart/related; type="application/octet-stream"'
resp = self._http_get(url, params, {'Accept': content_type})
return self._decode_multipart_message(resp.content, resp.headers)

Expand All @@ -587,11 +580,8 @@ def _http_get_multipart_image(self, url, image_format, **params):
raise ValueError(
'Image format "{}" is not supported.'.format(image_format)
)
content_type = (
'multipart/related; type="image/{image_format}"; '
'boundary="--{boundary}"'.format(
image_format=image_format, boundary=choose_boundary()
)
content_type = 'multipart/related; type="image/{image_format}"'.format(
image_format=image_format
)
resp = self._http_get(url, params, {'Accept': content_type})
return self._decode_multipart_message(resp.content, resp.headers)
Expand Down
6 changes: 3 additions & 3 deletions src/dicomweb_client/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def test_retrieve_instance(httpserver, client, cache_dir):
'/{sop_instance_uid}'.format(**locals())
)
assert request.path == expected_path
assert request.accept_mimetypes[0][0][:45] == headers['content-type'][:45]
assert request.accept_mimetypes[0][0][:43] == headers['content-type'][:43]


def test_retrieve_instance_pixeldata_jpeg(httpserver, client, cache_dir):
Expand Down Expand Up @@ -239,7 +239,7 @@ def test_retrieve_instance_pixeldata_jpeg(httpserver, client, cache_dir):
'/{sop_instance_uid}/frames/{frame_list}'.format(**locals())
)
assert request.path == expected_path
assert request.accept_mimetypes[0][0][:38] == headers['content-type'][:38]
assert request.accept_mimetypes[0][0][:36] == headers['content-type'][:36]


def test_retrieve_instance_pixeldata_jp2(httpserver, client, cache_dir):
Expand Down Expand Up @@ -267,4 +267,4 @@ def test_retrieve_instance_pixeldata_jp2(httpserver, client, cache_dir):
'/{sop_instance_uid}/frames/{frame_list}'.format(**locals())
)
assert request.path == expected_path
assert request.accept_mimetypes[0][0][:37] == headers['content-type'][:37]
assert request.accept_mimetypes[0][0][:35] == headers['content-type'][:35]

0 comments on commit ed7c13b

Please sign in to comment.