Skip to content
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

fix(embedded): third party cookies #20019

Merged
merged 5 commits into from
May 11, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,34 @@ export default async function callApi({
CACHE_AVAILABLE &&
(window.location && window.location.protocol) === 'https:'
) {
const supersetCache = await caches.open(CACHE_KEY);
const cachedResponse = await supersetCache.match(url);
if (cachedResponse) {
// if we have a cached response, send its ETag in the
// `If-None-Match` header in a conditional request
const etag = cachedResponse.headers.get('Etag') as string;
request.headers = { ...request.headers, 'If-None-Match': etag };
let supersetCache: Cache | null = null;
try {
supersetCache = await caches.open(CACHE_KEY);
const cachedResponse = await supersetCache.match(url);
if (cachedResponse) {
// if we have a cached response, send its ETag in the
// `If-None-Match` header in a conditional request
const etag = cachedResponse.headers.get('Etag') as string;
request.headers = { ...request.headers, 'If-None-Match': etag };
}
} catch {
// If superset is in an iframe and third-party cookies are disabled, caches.open throws
}

const response = await fetchWithRetry(url, request);

if (response.status === HTTP_STATUS_NOT_MODIFIED) {
if (supersetCache && response.status === HTTP_STATUS_NOT_MODIFIED) {
const cachedFullResponse = await supersetCache.match(url);
if (cachedFullResponse) {
return cachedFullResponse.clone();
}
throw new Error('Received 304 but no content is cached!');
}
if (response.status === HTTP_STATUS_OK && response.headers.get('Etag')) {
if (
supersetCache &&
response.status === HTTP_STATUS_OK &&
response.headers.get('Etag')
) {
supersetCache.delete(url);
supersetCache.put(url, response.clone());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,26 @@ export default function makeApi<
Payload = SupersetPayload,
Result = JsonObject,
T extends ParseMethod = ParseMethod,
>({
endpoint,
method,
requestType: requestType_,
responseType,
processResponse,
...requestOptions
}: SupersetApiFactoryOptions & {
/**
* How to parse response, choose from: 'json' | 'text' | 'raw'.
*/
responseType?: T;
/**
* Further process parsed response
*/
processResponse?(result: ParsedResponseType<T>): Result;
}) {
>(
options: SupersetApiFactoryOptions & {
/**
* How to parse response, choose from: 'json' | 'text' | 'raw'.
*/
responseType?: T;
/**
* Further process parsed response
*/
processResponse?(result: ParsedResponseType<T>): Result;
},
) {
const {
endpoint,
method,
requestType: requestType_,
responseType,
processResponse,
...requestOptions
} = options;
// use `search` payload (searchParams) when it's a GET request
const requestType =
requestType_ || (isPayloadless(method) ? 'search' : 'json');
Expand Down