Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Mikael Finstad <finstaden@gmail.com>
  • Loading branch information
aduh95 and mifi authored Nov 8, 2022
1 parent 1cf26ff commit e53d40c
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions packages/@uppy/companion-client/src/RequestClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,7 @@ export default class RequestClient {
*/
async preflight (path) {
const allowedHeadersCached = allowedHeadersCache.get(this.hostname)
if (allowedHeadersCached != null) {
// The cache may contain a promise that will resolve to undefined if the
// fetch call fails. In that case, we want to retry sending a preflight response.
const cachedResult = await allowedHeadersCached
if (cachedResult != null) return cachedResult
}
if (allowedHeadersCached != null) return allowedHeadersCached

const fallbackAllowedHeaders = ['accept', 'content-type', 'uppy-auth-token']

Expand All @@ -134,14 +129,13 @@ export default class RequestClient {
this.uppy.log(`[CompanionClient] unable to make preflight request ${err}`, 'warning')
// If the user gets a network error or similar, we should try preflight
// again next time, or else we might get incorrect behaviour.
allowedHeadersCache.delete(this.hostname)
return undefined
allowedHeadersCache.delete(this.hostname) // re-fetch next time
return fallbackAllowedHeaders
}
})()

allowedHeadersCache.set(this.hostname, promise)
const allowedHeadersNew = await promise
return allowedHeadersNew ?? fallbackAllowedHeaders
return promise
}

async preflightAndHeaders (path) {
Expand Down

0 comments on commit e53d40c

Please sign in to comment.