diff --git a/src/app/services/actions/query-action-creator-util.ts b/src/app/services/actions/query-action-creator-util.ts index eae931a84..77208b159 100644 --- a/src/app/services/actions/query-action-creator-util.ts +++ b/src/app/services/actions/query-action-creator-util.ts @@ -11,6 +11,7 @@ import { IAction } from '../../../types/action'; import { ContentType } from '../../../types/enums'; import { IQuery } from '../../../types/query-runner'; import { IRequestOptions } from '../../../types/request'; +import { IStatus } from '../../../types/status'; import { encodeHashCharacters } from '../../utils/query-url-sanitization'; import { authProvider, GraphClient } from '../graph-client'; import { DEFAULT_USER_SCOPES } from '../graph-constants'; @@ -29,13 +30,13 @@ export async function anonymousRequest( query: IQuery, getState: Function ) { + const { proxyUrl, queryRunnerStatus } = getState(); + const { graphUrl, options } = createAnonymousRequest(query, proxyUrl, queryRunnerStatus); dispatch(queryRunningStatus(true)); - const { proxyUrl } = getState(); - const { graphUrl, options } = createAnonymousRequest(query, proxyUrl); return fetch(graphUrl, options); } -export function createAnonymousRequest(query: IQuery, proxyUrl: string) { +export function createAnonymousRequest(query: IQuery, proxyUrl: string, queryRunnerStatus: IStatus) { const escapedUrl = encodeURIComponent(query.sampleUrl); const graphUrl = `${proxyUrl}?url=${escapedUrl}`; const sampleHeaders: any = {}; @@ -47,13 +48,18 @@ export function createAnonymousRequest(query: IQuery, proxyUrl: string) { } const authToken = '{token:https://graph.microsoft.com/}'; - const headers = { + let headers = { Authorization: `Bearer ${authToken}`, 'Content-Type': 'application/json', SdkVersion: 'GraphExplorer/4.0', ...sampleHeaders }; + if (queryRunnerStatus && !queryRunnerStatus.ok) { + const updatedHeaders = { ...headers, 'cache-control': 'no-cache', pragma: 'no-cache' } + headers = updatedHeaders; + } + const options: IRequestOptions = { method: query.selectedVerb, headers diff --git a/src/tests/utils/proxy-url.spec.ts b/src/tests/utils/proxy-url.spec.ts index 169594da7..080c30ff6 100644 --- a/src/tests/utils/proxy-url.spec.ts +++ b/src/tests/utils/proxy-url.spec.ts @@ -3,6 +3,7 @@ import fetch from 'isomorphic-fetch'; import { isValidHttpsUrl } from '../../app/utils/external-link-validation'; import { createAnonymousRequest } from '../../app/services/actions/query-action-creator-util'; import { IQuery } from '../../types/query-runner'; +import { IStatus } from '../../types/status'; describe('Sandbox api fetch should', () => { @@ -24,7 +25,16 @@ describe('Sandbox api fetch should', () => { sampleBody: '' } - const { graphUrl, options } = createAnonymousRequest(query, proxyUrl); + const queryRunnerStatus: IStatus = { + messageType: 0, + ok: false, + status: 400, + statusText: '', + duration: 100, + hint: '' + } + + const { graphUrl, options } = createAnonymousRequest(query, proxyUrl, queryRunnerStatus); const response = await fetch(graphUrl, options); expect(response.ok).toBe(true); });