diff --git a/src/lib/hash-params.test.ts b/src/lib/hash-params.test.ts index fad47e7d3..77b4b8500 100644 --- a/src/lib/hash-params.test.ts +++ b/src/lib/hash-params.test.ts @@ -22,6 +22,9 @@ test('getHashParams', () => { expect(getHashParams('#title=hello%20world')).toEqual({ title: 'hello world', }) + expect(getHashParams('#profileAccepts=application%2Fjson')).toEqual({ + profileAccepts: 'application/json', + }) expect(getHashParams('#abc=bcd')).toEqual({}) expect(getHashParams('garbage')).toEqual({}) }) diff --git a/src/lib/hash-params.ts b/src/lib/hash-params.ts index 6d6ca3e5a..e68c80639 100644 --- a/src/lib/hash-params.ts +++ b/src/lib/hash-params.ts @@ -2,6 +2,7 @@ import {ViewMode} from '../lib/view-mode' export interface HashParams { profileURL?: string + profileAccepts?: string title?: string localProfilePath?: string viewMode?: ViewMode @@ -36,6 +37,8 @@ export function getHashParams(hashContents = window.location.hash): HashParams { result.title = value } else if (key === 'localProfilePath') { result.localProfilePath = value + } else if (key === 'profileAccepts') { + result.profileAccepts = value } else if (key === 'view') { const mode = getViewMode(value) if (mode !== null) { diff --git a/src/views/application.tsx b/src/views/application.tsx index d3fba1547..980510fab 100644 --- a/src/views/application.tsx +++ b/src/views/application.tsx @@ -424,7 +424,7 @@ export class Application extends StatelessComponent { } async maybeLoadHashParamProfile() { - const {profileURL} = this.props.hashParams + const {profileURL, profileAccepts} = this.props.hashParams if (profileURL) { if (!canUseXHR) { alert( @@ -433,7 +433,14 @@ export class Application extends StatelessComponent { return } this.loadProfile(async () => { - const response: Response = await fetch(profileURL) + const fetchOpts: RequestInit = {} + if (profileAccepts) { + fetchOpts['headers'] = { + Accept: profileAccepts, + } + } + + const response: Response = await fetch(profileURL, fetchOpts) let filename = new URL(profileURL, window.location.href).pathname if (filename.includes('/')) { filename = filename.slice(filename.lastIndexOf('/') + 1)