Skip to content

Commit

Permalink
feat: make sure 304 works
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Feb 15, 2022
1 parent 88e14a6 commit 516a27a
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions packages/gatsby-core-utils/src/fetch-remote-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async function fetchFile({
}: IFetchRemoteFileOptions): Promise<string> {
// global introduced in gatsby 4.0.0
const BUILD_ID = global.__GATSBY?.buildId ?? ``
const fileDirectory = cache ? cache.directory : directory
const fileDirectory = (cache ? cache.directory : directory) as string
const storage = getStorage(getDatabaseDir())

if (!cache && !directory) {
Expand Down Expand Up @@ -172,25 +172,17 @@ async function fetchFile({
}

const digest = createContentDigest(url)
await fs.ensureDir(path.join(fileDirectory as string, digest))
await fs.ensureDir(path.join(fileDirectory, digest))

const tmpFilename = createFilePath(
fileDirectory as string,
`tmp-${digest}`,
ext
)
const tmpFilename = createFilePath(fileDirectory, `tmp-${digest}`, ext)
const response = await requestRemoteNode(
url,
headers,
tmpFilename,
httpOptions
)

const filename = createFilePath(
path.join(fileDirectory as string, digest),
name,
ext
)
const filename = createFilePath(path.join(fileDirectory, digest), name, ext)
if (response.statusCode === 200) {
// Save the response headers for future requests.
// If the user did not provide an extension and we couldn't get one from remote file, try and guess one
Expand All @@ -207,7 +199,6 @@ async function fetchFile({
await setInFlightObject(url, BUILD_ID, {
cacheKey,
extension: ext,
headers,
headers: response.headers.etag ? { etag: response.headers.etag } : {},
directory: fileDirectory,
path: filename.replace(fileDirectory, ``),
Expand Down

0 comments on commit 516a27a

Please sign in to comment.