@@ -57,23 +57,24 @@ function assertMediaTypeIsValid(mediaType) {
5757} 
5858
5959/** 
60-  * Parses media type and extracts its type and subtype . 
60+  * Builds an accept header field value for HTTP GET multipart request messages . 
6161 * 
62-  * @param  mediaType e.g. image/jpeg 
63-  * @private  
64-  */ 
65- function  parseMediaType ( mediaType )  { 
66-   assertMediaTypeIsValid ( mediaType ) ; 
67- 
68-   return  mediaType . split ( '/' ) ; 
69- } 
70- 
71- /** 
72-  * Builds an accept header field value for HTTP GET multipart request 
73-  messages. 
62+  * Takes in input a media types array of type [{mediaType, transferSyntaxUID}, ... ], 
63+  * cross-compares with a map defining the supported media types per transferSyntaxUID 
64+  * and finally composes a string for the accept header field value as in example below: 
65+  * 
66+  * "multipart/related; type="image/x-dicom-rle"; transfer-syntax=1.2.840.10008.1.2.5, 
67+  *  multipart/related; type="image/jpeg"; transfer-syntax=1.2.840.10008.1.2.4.50, 
68+  *  multipart/related; type="application/octet-stream"; transfer-syntax=*" 
69+  * 
70+  * NOTE: the xhr request will try to fetch with all the transfer-syntax syntaxes 
71+  * specified in the accept header field value in descending order. 
72+  * The first element ("image/x-dicom-rle" in this example) has the highest priority. 
7473 * 
7574 * @param  {Array } mediaTypes Acceptable media types 
7675 * @param  {Object } supportedMediaTypes Supported media types 
76+  * 
77+  * @returns  {string } accept header field value 
7778 */ 
7879
7980function  buildMultipartAcceptHeaderFieldValue ( mediaTypes ,  supportedMediaTypes )  { 
@@ -87,6 +88,12 @@ function buildMultipartAcceptHeaderFieldValue(mediaTypes, supportedMediaTypes) {
8788    ) ; 
8889  } 
8990
91+   const  supportedMediaTypesArray  =  Object . values ( supportedMediaTypes ) . flat ( 1 ) ; 
92+ 
93+   supportedMediaTypesArray . forEach ( ( supportedMediaType )  =>  { 
94+     assertMediaTypeIsValid ( supportedMediaType ) ; 
95+   } ) ; 
96+ 
9097  const  fieldValueParts  =  [ ] ; 
9198
9299  mediaTypes . forEach ( ( item )  =>  { 
@@ -96,9 +103,9 @@ function buildMultipartAcceptHeaderFieldValue(mediaTypes, supportedMediaTypes) {
96103
97104    let  fieldValue  =  `multipart/related; type="${ mediaType }  ; 
98105
99-     // SupportedMediaTypes  is a lookup table that maps Transfer Syntax UID 
106+     // supportedMediaTypesArray  is a lookup table that maps Transfer Syntax UID 
100107    // to one or more Media Types 
101-     if  ( ! Object . values ( supportedMediaTypes ) . flat ( 1 ) . includes ( mediaType ) )  { 
108+     if  ( ! supportedMediaTypesArray . includes ( mediaType ) )  { 
102109      if  ( 
103110        ( ! mediaType . endsWith ( '/*' )  ||  ! mediaType . endsWith ( '/' ) )  && 
104111        mediaType  !==  'application/octet-stream' 
@@ -118,10 +125,10 @@ function buildMultipartAcceptHeaderFieldValue(mediaTypes, supportedMediaTypes) {
118125        const  expectedMediaTypes  =  supportedMediaTypes [ transferSyntaxUID ] ; 
119126
120127        if  ( ! expectedMediaTypes . includes ( mediaType ) )  { 
121-           const  actualType  =  parseMediaType ( mediaType ) [ 0 ] ; 
128+           const  actualType  =  mediaType . split ( '/' ) [ 0 ] ; 
122129
123130          expectedMediaTypes . map ( ( expectedMediaType )  =>  { 
124-             const  expectedType  =  parseMediaType ( expectedMediaType ) [ 0 ] ; 
131+             const  expectedType  =  expectedMediaType . split ( '/' ) [ 0 ] ; 
125132
126133            const  haveSameType  =  actualType  ===  expectedType ; 
127134
@@ -169,6 +176,8 @@ function getPixelData(uri, imageId, mediaTypes) {
169176    ) , 
170177  } ; 
171178
179+   console . info ( 'bellla' ,  headers ) ; 
180+ 
172181  return  new  Promise ( ( resolve ,  reject )  =>  { 
173182    const  loadPromise  =  xhrRequest ( uri ,  imageId ,  headers ) ; 
174183
0 commit comments