1
- import { multipartEncode , multipartDecode } from './message.js' ;
2
-
3
-
1
+ import { multipartEncode , multipartDecode , addHeaders } from './message.js' ;
4
2
5
3
function isObject ( obj ) {
6
4
return typeof obj === 'object' && obj !== null ;
@@ -225,7 +223,7 @@ class DICOMwebClient {
225
223
let requestInstance = request . instance ? request . instance : new XMLHttpRequest ( ) ;
226
224
227
225
requestInstance . open ( method , url , true ) ;
228
- if ( 'responseType' in request ) {
226
+ if ( request . responseType ) {
229
227
requestInstance . responseType = request . responseType ;
230
228
}
231
229
@@ -256,12 +254,16 @@ class DICOMwebClient {
256
254
requestInstance . onreadystatechange = ( ) => {
257
255
if ( requestInstance . readyState === 4 ) {
258
256
if ( requestInstance . status === 200 ) {
259
- const contentType = requestInstance . getResponseHeader ( 'Content-Type' ) ;
257
+ const contentType = requestInstance . getResponseHeader (
258
+ 'Content-Type' ,
259
+ ) ;
260
+ const headers = requestInstance . getAllResponseHeaders ( ) ;
260
261
// Automatically distinguishes between multipart and singlepart in an array buffer, and
261
262
// converts them into a consistent type.
262
263
if ( contentType && contentType . indexOf ( 'multipart' ) !== - 1 ) {
263
264
resolve ( multipartDecode ( requestInstance . response ) ) ;
264
265
} else if ( requestInstance . responseType === 'arraybuffer' ) {
266
+ addHeaders ( requestInstance . response , headers ) ;
265
267
resolve ( [ requestInstance . response ] ) ;
266
268
} else {
267
269
resolve ( requestInstance . response ) ;
@@ -295,10 +297,8 @@ class DICOMwebClient {
295
297
} ;
296
298
297
299
// Event triggered while download progresses
298
- if ( 'progressCallback' in request ) {
299
- if ( typeof request . progressCallback === 'function' ) {
300
- requestInstance . onprogress = request . progressCallback ;
301
- }
300
+ if ( typeof request . progressCallback === 'function' ) {
301
+ requestInstance . onprogress = request . progressCallback ;
302
302
}
303
303
304
304
if ( requestHooks && areValidRequestHooks ( requestHooks ) ) {
@@ -311,13 +311,11 @@ class DICOMwebClient {
311
311
}
312
312
313
313
// Add withCredentials to request if needed
314
- if ( 'withCredentials' in request ) {
315
- if ( request . withCredentials ) {
316
- requestInstance . withCredentials = true ;
317
- }
314
+ if ( request . withCredentials ) {
315
+ requestInstance . withCredentials = true ;
318
316
}
319
317
320
- if ( 'data' in request ) {
318
+ if ( request . data ) {
321
319
requestInstance . send ( request . data ) ;
322
320
} else {
323
321
requestInstance . send ( ) ;
@@ -594,6 +592,7 @@ class DICOMwebClient {
594
592
'image/gif' ,
595
593
'image/png' ,
596
594
'image/jp2' ,
595
+ 'image/*' ,
597
596
] ;
598
597
} else {
599
598
supportedMediaTypes = {
@@ -608,6 +607,7 @@ class DICOMwebClient {
608
607
'1.2.840.10008.1.2.4.91' : [ 'image/jp2' ] ,
609
608
'1.2.840.10008.1.2.4.92' : [ 'image/jpx' ] ,
610
609
'1.2.840.10008.1.2.4.93' : [ 'image/jpx' ] ,
610
+ '*' : [ 'image/*' ] ,
611
611
} ;
612
612
613
613
if ( byteRange ) {
@@ -961,7 +961,7 @@ class DICOMwebClient {
961
961
} ) ;
962
962
963
963
if ( ! fieldValueParts . length ) {
964
- throw new Error ( `No acceptable media types found among ${ JSON . stringify ( mediaTypes ) } ` ) ;
964
+ throw new Error ( `No acceptable media types found among ${ JSON . stringify ( mediaTypes ) } testing against ${ JSON . stringify ( acceptableMediaTypes ) } ` ) ;
965
965
}
966
966
967
967
return fieldValueParts . join ( ', ' ) ;
@@ -1227,7 +1227,7 @@ class DICOMwebClient {
1227
1227
debugLog ( `retrieve metadata of instance ${ options . sopInstanceUID } ` ) ;
1228
1228
const url = `${ this . wadoURL } /studies/${ options . studyInstanceUID } /series/${ options . seriesInstanceUID } /instances/${ options . sopInstanceUID } /metadata` ;
1229
1229
1230
- const request = getRequestOptions ( options . request )
1230
+ const request = getRequestOptions ( options . request ) ;
1231
1231
return this . _httpGetApplicationJson ( url , { } , request ) ;
1232
1232
}
1233
1233
@@ -1276,6 +1276,7 @@ class DICOMwebClient {
1276
1276
const { mediaTypes } = options ;
1277
1277
1278
1278
const request = getRequestOptions ( options . request )
1279
+ request . responseType = 'arraybuffer' ;
1279
1280
1280
1281
if ( ! mediaTypes ) {
1281
1282
return this . _httpGetMultipartApplicationOctetStream (
@@ -1317,7 +1318,6 @@ class DICOMwebClient {
1317
1318
supportedMediaTypes ,
1318
1319
) ,
1319
1320
} ;
1320
- request . responseType = 'arraybuffer' ;
1321
1321
return this . _httpGet ( url , headers , request ) ;
1322
1322
}
1323
1323
0 commit comments