Skip to content
Open
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
10 changes: 7 additions & 3 deletions src/server/publisher-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function requestAcceptsTextHtml(req: Request) {
type AssetInit = {
status?: number,
headers?: Record<string, string>,
cache?: 'extended' | 'never' | null,
cache?: 'extended' | 'never' | null | string,
};

export class PublisherServer {
Expand Down Expand Up @@ -238,6 +238,8 @@ export class PublisherServer {
case 'never':
cacheControlValue = 'no-store';
break;
default:
cacheControlValue = init.cache;
}
headers['Cache-Control'] = cacheControlValue;
}
Expand All @@ -264,7 +266,7 @@ export class PublisherServer {
});
}

async serveRequest(request: Request): Promise<Response | null> {
async serveRequest(request: Request, cache: string): Promise<Response | null> {

// Only handle GET and HEAD
if (request.method !== 'GET' && request.method !== 'HEAD') {
Expand All @@ -274,10 +276,12 @@ export class PublisherServer {
const url = new URL(request.url);
const pathname = url.pathname;

const doCache = cache || (this.testExtendedCache(pathname) ? 'extended' : null);

const asset = this.getMatchingAsset(pathname);
if (asset != null) {
return this.serveAsset(request, asset, {
cache: this.testExtendedCache(pathname) ? 'extended' : null,
cache: doCache,
});
}

Expand Down