fix(embedded): third party cookies (#20019)
* debugging * logging * add comment * remove logging * Update superset-frontend/packages/superset-ui-core/src/connection/callApi/callApi.ts Co-authored-by: David Aaron Suddjian <1858430+suddjian@users.noreply.github.com> Co-authored-by: David Aaron Suddjian <aasuddjian@gmail.com> Co-authored-by: David Aaron Suddjian <1858430+suddjian@users.noreply.github.com>
This commit is contained in:
parent
9cf9f97a0c
commit
3e36d4a0a1
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Reference in New Issue