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

UBERF-7425: Fix some CF caching issues #5936

Merged
merged 1 commit into from
Jun 27, 2024
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
12 changes: 10 additions & 2 deletions server/front/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ async function getFile (
preConditions.IfModifiedSince(req.headers, { lastModified: new Date(stat.modifiedOn) }) === 'notModified'
) {
// Matched, return not modified
res.statusCode = 304
res.writeHead(304, {
'content-type': stat.contentType,
etag: stat.etag,
'last-modified': new Date(stat.modifiedOn).toISOString(),
'cache-control': cacheControlValue
})
res.end()
return
}
Expand Down Expand Up @@ -375,7 +380,10 @@ export function start (
res.status(404).send()
return
}
const isImage = blobInfo.contentType.includes('image/')

// try image and octet streams
const isImage =
blobInfo.contentType.includes('image/') || blobInfo.contentType.includes('application/octet-stream')

if (token === undefined) {
if (blobInfo !== undefined && !isImage) {
Expand Down
10 changes: 5 additions & 5 deletions server/front/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request } from 'express'
import type { IncomingMessage } from 'http'

export const ETagSupport = {
isWeak (etag: string): boolean {
Expand Down Expand Up @@ -30,7 +30,7 @@ function toList (value: string): string[] {
}

export const preConditions = {
IfMatch: (headers: Request['headers'], state: { etag: string }): 'fetch' | 'notModified' => {
IfMatch: (headers: IncomingMessage['headers'], state: { etag: string }): 'fetch' | 'notModified' => {
const header = (headers as any)['if-match']
if (header == null) {
return 'fetch'
Expand All @@ -40,7 +40,7 @@ export const preConditions = {
}
return toList(header).some((etag) => ETagSupport.strongMatch(etag, state.etag)) ? 'notModified' : 'fetch'
},
IfNoneMatch: (headers: Request['headers'], state: { etag: string }): 'fetch' | 'notModified' => {
IfNoneMatch: (headers: IncomingMessage['headers'], state: { etag: string }): 'fetch' | 'notModified' => {
const header = (headers as any)['if-none-match']
if (header == null) {
return 'fetch'
Expand All @@ -52,7 +52,7 @@ export const preConditions = {
return toList(header).some((etag) => ETagSupport.weakMatch(etag, state.etag)) ? 'notModified' : 'fetch'
}
},
IfModifiedSince: (headers: Request['headers'], state: { lastModified: Date }): 'fetch' | 'notModified' => {
IfModifiedSince: (headers: IncomingMessage['headers'], state: { lastModified: Date }): 'fetch' | 'notModified' => {
if ((headers as any)['if-none-match'] != null) {
return 'fetch'
}
Expand All @@ -67,7 +67,7 @@ export const preConditions = {
}
return state.lastModified.getTime() <= date ? 'notModified' : 'fetch'
},
IfUnmodifiedSince: (headers: Request['headers'], state: { lastModified: Date }): 'fetch' | 'failed' => {
IfUnmodifiedSince: (headers: IncomingMessage['headers'], state: { lastModified: Date }): 'fetch' | 'failed' => {
if ((headers as any)['if-match'] != null) {
return 'fetch'
}
Expand Down