mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 03:40:48 +00:00
UBERF-7425: Fix some CF caching issues (#5936)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
9217aff35c
commit
f9aabe98c3
@ -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
|
||||
}
|
||||
@ -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) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Request } from 'express'
|
||||
import type { IncomingMessage } from 'http'
|
||||
|
||||
export const ETagSupport = {
|
||||
isWeak (etag: string): boolean {
|
||||
@ -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'
|
||||
@ -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'
|
||||
@ -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'
|
||||
}
|
||||
@ -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'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user