Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/lib/hash-params.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
})
3 changes: 3 additions & 0 deletions src/lib/hash-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {ViewMode} from '../lib/view-mode'

export interface HashParams {
profileURL?: string
profileAccepts?: string
title?: string
localProfilePath?: string
viewMode?: ViewMode
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions src/views/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ export class Application extends StatelessComponent<ApplicationProps> {
}

async maybeLoadHashParamProfile() {
const {profileURL} = this.props.hashParams
const {profileURL, profileAccepts} = this.props.hashParams
if (profileURL) {
if (!canUseXHR) {
alert(
Expand All @@ -433,7 +433,14 @@ export class Application extends StatelessComponent<ApplicationProps> {
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)
Expand Down