-
Notifications
You must be signed in to change notification settings - Fork 264
fix: use array of mediatypes and transferSyntax when calling a get xhrRequest for image loading #477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Punzo
wants to merge
3
commits into
cornerstonejs:master
Choose a base branch
from
Punzo:IDC2934
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix: use array of mediatypes and transferSyntax when calling a get xhrRequest for image loading #477
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /** | ||
| * Asserts that a given media type is valid. | ||
| * | ||
| * @params {String} mediaType media type | ||
| */ | ||
|
|
||
| export default function assertMediaTypeIsValid(mediaType) { | ||
| if (!mediaType) { | ||
| throw new Error(`Not a valid media type: ${mediaType}`); | ||
| } | ||
| const sepIndex = mediaType.indexOf('/'); | ||
|
|
||
| if (sepIndex === -1) { | ||
| throw new Error(`Not a valid media type: ${mediaType}`); | ||
| } | ||
| const mediaTypeType = mediaType.slice(0, sepIndex); | ||
|
|
||
| const types = ['application', 'image', 'text', 'video']; | ||
|
|
||
| if (!types.includes(mediaTypeType)) { | ||
| throw new Error(`Not a valid media type: ${mediaType}`); | ||
| } | ||
| if (mediaType.slice(sepIndex + 1).includes('/')) { | ||
| throw new Error(`Not a valid media type: ${mediaType}`); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| const jllMediaType = 'image/jll'; | ||
| const jllTransferSyntaxUIDlossless = '1.2.840.10008.1.2.4.70'; | ||
|
|
||
| export { jllMediaType, jllTransferSyntaxUIDlossless }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| const jlsMediaType = 'image/jls'; | ||
| const jlsTransferSyntaxUIDlossless = '1.2.840.10008.1.2.4.80'; | ||
| const jlsTransferSyntaxUID = '1.2.840.10008.1.2.4.81'; | ||
|
|
||
| export { jlsMediaType, jlsTransferSyntaxUIDlossless, jlsTransferSyntaxUID }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| const jp2MediaType = 'image/jp2'; | ||
| const jp2TransferSyntaxUIDlossless = '1.2.840.10008.1.2.4.90'; | ||
| const jp2TransferSyntaxUID = '1.2.840.10008.1.2.4.91'; | ||
|
|
||
| export { jp2MediaType, jp2TransferSyntaxUIDlossless, jp2TransferSyntaxUID }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| const jpegMediaType = 'image/jpeg'; | ||
| const jpegTransferSyntaxUIDlossy1 = '1.2.840.10008.1.2.4.50'; | ||
| const jpegTransferSyntaxUIDlossy2 = '1.2.840.10008.1.2.4.51'; | ||
| const jpegTransferSyntaxUIDlossless = '1.2.840.10008.1.2.4.57'; | ||
|
|
||
| export { | ||
| jpegMediaType, | ||
| jpegTransferSyntaxUIDlossy1, | ||
| jpegTransferSyntaxUIDlossy2, | ||
| jpegTransferSyntaxUIDlossless, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| const octetStreamMediaType = 'application/octet-stream'; | ||
| const octetStreamTransferSyntaxUID = '*'; | ||
|
|
||
| export { octetStreamMediaType, octetStreamTransferSyntaxUID }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| const xdicomrleMediaType = 'image/x-dicom-rle'; | ||
| const xdicomrleTransferSyntaxUID = '1.2.840.10008.1.2.5'; | ||
|
|
||
| export { xdicomrleMediaType, xdicomrleTransferSyntaxUID }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { | ||
| xdicomrleMediaType, | ||
| xdicomrleTransferSyntaxUID, | ||
| } from './mediaTypeXDicomRLE.js'; | ||
| import { | ||
| jpegMediaType, | ||
| jpegTransferSyntaxUIDlossy1, | ||
| jpegTransferSyntaxUIDlossy2, | ||
| jpegTransferSyntaxUIDlossless, | ||
| } from './mediaTypeJPEG.js'; | ||
| import { jllMediaType, jllTransferSyntaxUIDlossless } from './mediaTypeJLL.js'; | ||
| import { | ||
| jlsMediaType, | ||
| jlsTransferSyntaxUID, | ||
| jlsTransferSyntaxUIDlossless, | ||
| } from './mediaTypeJLS.js'; | ||
| import { | ||
| jp2MediaType, | ||
| jp2TransferSyntaxUID, | ||
| jp2TransferSyntaxUIDlossless, | ||
| } from './mediaTypeJP2.js'; | ||
| import { | ||
| octetStreamMediaType, | ||
| octetStreamTransferSyntaxUID, | ||
| } from './mediaTypeOctetStream.js'; | ||
|
|
||
| // NOTE: the position of the elements in the array indicates the mediaType | ||
| // priority when fetching an image. An element at the beginning of the array | ||
| // has the highest priority. | ||
| const mediaTypes = [ | ||
| { | ||
| mediaType: xdicomrleMediaType, | ||
| transferSyntaxUID: xdicomrleTransferSyntaxUID, | ||
| }, | ||
| { | ||
| mediaType: jpegMediaType, | ||
| transferSyntaxUID: jpegTransferSyntaxUIDlossy1, | ||
| }, | ||
| { | ||
| mediaType: jpegMediaType, | ||
| transferSyntaxUID: jpegTransferSyntaxUIDlossy2, | ||
| }, | ||
| { | ||
| mediaType: jpegMediaType, | ||
| transferSyntaxUID: jpegTransferSyntaxUIDlossless, | ||
| }, | ||
| { | ||
| mediaType: jllMediaType, | ||
| transferSyntaxUID: jllTransferSyntaxUIDlossless, | ||
| }, | ||
| { | ||
| mediaType: jlsMediaType, | ||
| transferSyntaxUID: jlsTransferSyntaxUIDlossless, | ||
| }, | ||
| { | ||
| mediaType: jlsMediaType, | ||
| transferSyntaxUID: jlsTransferSyntaxUID, | ||
| }, | ||
| { | ||
| mediaType: jp2MediaType, | ||
| transferSyntaxUID: jp2TransferSyntaxUIDlossless, | ||
| }, | ||
| { | ||
| mediaType: jp2MediaType, | ||
| transferSyntaxUID: jp2TransferSyntaxUID, | ||
| }, | ||
| { | ||
| mediaType: octetStreamMediaType, | ||
| transferSyntaxUID: octetStreamTransferSyntaxUID, | ||
| }, | ||
| ]; | ||
|
|
||
| export { mediaTypes }; |
50 changes: 50 additions & 0 deletions
50
src/shared/mediaTypesUtils/multipartAcceptHeaderFieldValue.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import assertMediaTypeIsValid from './assertMediaTypeIsValid.js'; | ||
| import { mediaTypes } from './mediaTypes.js'; | ||
|
|
||
| /** | ||
| * Builds an accept header field value for HTTP GET multipart request messages. | ||
| * | ||
| * Takes in input a media types array of type [{mediaType, transferSyntaxUID}, ... ] | ||
| * and finally composes a string for the accept header field value as in example below: | ||
| * | ||
| * "multipart/related; type="image/x-dicom-rle"; transfer-syntax=1.2.840.10008.1.2.5, | ||
| * multipart/related; type="image/jpeg"; transfer-syntax=1.2.840.10008.1.2.4.50, | ||
| * multipart/related; type="application/octet-stream"; transfer-syntax=*" | ||
| * | ||
| * NOTE: the xhr request will try to fetch with all the transfer-syntax syntaxes | ||
| * specified in the accept header field value in descending order. | ||
| * The first element ("image/x-dicom-rle" in this example) has the highest priority. | ||
| * | ||
| * @param {Array} mediaTypes Acceptable media types | ||
| * | ||
| * @returns {string} accept header field value | ||
| */ | ||
|
|
||
| export default function buildMultipartAcceptHeaderFieldValue(mediaTypes) { | ||
| if (!Array.isArray(mediaTypes)) { | ||
| throw new Error('Acceptable media types must be provided as an Array'); | ||
| } | ||
|
|
||
| const fieldValueParts = []; | ||
|
|
||
| mediaTypes.forEach((item) => { | ||
| const { transferSyntaxUID, mediaType } = item; | ||
|
|
||
| assertMediaTypeIsValid(mediaType); | ||
|
|
||
| let fieldValue = `multipart/related; type="${mediaType}"`; | ||
|
|
||
| if (transferSyntaxUID) { | ||
| fieldValue += `; transfer-syntax=${transferSyntaxUID}`; | ||
| } | ||
|
|
||
| fieldValueParts.push(fieldValue); | ||
| }); | ||
|
|
||
| return fieldValueParts.join(', '); | ||
| } | ||
|
|
||
| const multipartAcceptHeaderFieldValue = | ||
| buildMultipartAcceptHeaderFieldValue(mediaTypes); | ||
|
|
||
| export { multipartAcceptHeaderFieldValue }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should not have
type="${mediaType}"it should betype=${mediaType}. Double checking with @wayfarer3130There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @sedghi,
Referring to azure dicom docs, type shoud be in double quotes. Otherwise, 406 response status will be returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the DICOM standard it depends on the version, and according to the original RFC for multipart related, the quotes are NOT permitted, although every example in the document shows them. Including them drops the speed by approximately a half because it requires a full extra CORS request, assuming the CORS is used. Not including htem breaks Azure, so the DICOM committee has agreed to a statement that clients need to have an option to fallback from one version to the other. For cornerstone, that is determined by a configuration parameter on the specific back end request, so that you can include them when configured to do so, and omit them otherwise.