-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: better handling of Accept headers (#20)
- Loading branch information
Showing
3 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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,29 @@ | ||
/** | ||
* Copyright 2018-2021 BOTLabs GmbH. | ||
* | ||
* This source code is licensed under the BSD 4-Clause "Original" license | ||
* found in the LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
function processAcceptHeaders(headers) { | ||
const acceptedTypes = new Set([...headers.split(',').map((c) => c.trim())]) | ||
let exportType | ||
let defaultExport | ||
let responseContentType | ||
if (acceptedTypes.has('application/did+json')) { | ||
exportType = 'application/json' | ||
defaultExport = {} | ||
responseContentType = 'application/did+json' | ||
} else { | ||
exportType = 'application/ld+json' | ||
defaultExport = { '@context': ['https://www.w3.org/ns/did/v1'] } | ||
responseContentType = 'application/did+ld+json' | ||
} | ||
return { | ||
exportType, | ||
defaultExport, | ||
responseContentType | ||
} | ||
} | ||
|
||
module.exports = { processAcceptHeaders } |