Skip to content

Commit

Permalink
reset etag with pathname only (#1418)
Browse files Browse the repository at this point in the history
* reset etag with pathname only

* Update dev.ts

* Update dev.ts

Co-authored-by: Fred K. Schott <fkschott@gmail.com>
  • Loading branch information
dishuostec and FredKSchott committed Oct 29, 2020
1 parent 619ef2c commit 7a42bdd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions snowpack/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1153,29 +1153,31 @@ export async function startDevServer(commandOptions: CommandOptions): Promise<Sn
res: http.ServerResponse,
{handleError}: {handleError?: boolean} = {},
) {
const reqPath = req.url!;
const reqUrl = req.url!;
// Check if a configured proxy matches the request.
const requestProxy = getRequestProxy(reqPath);
const requestProxy = getRequestProxy(reqUrl);
if (requestProxy) {
return requestProxy(req, res);
}
// Check if we can send back an optimized 304 response
const quickETagCheck = req.headers['if-none-match'];
if (quickETagCheck && quickETagCheck === knownETags.get(reqPath)) {
if (quickETagCheck && quickETagCheck === knownETags.get(reqUrl)) {
logger.debug(`optimized etag! sending 304...`);
res.writeHead(304, {'Access-Control-Allow-Origin': '*'});
res.end();
return;
}
// Otherwise, load the file and respond if successful.
try {
const result = await loadUrl(reqPath, {allowStale: true, encoding: null});
const result = await loadUrl(reqUrl, {allowStale: true, encoding: null});
sendResponseFile(req, res, result);
if (result.checkStale) {
await result.checkStale();
}
if (result.contents) {
knownETags.set(reqPath, etag(result.contents, {weak: true}));
const tag = etag(result.contents, {weak: true});
const reqPath = decodeURI(url.parse(reqUrl).pathname!);
knownETags.set(reqPath, tag);
}
return;
} catch (err) {
Expand Down

1 comment on commit 7a42bdd

@vercel
Copy link

@vercel vercel bot commented on 7a42bdd Oct 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.