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

reset etag with pathname only #1418

Merged
merged 3 commits into from
Oct 29, 2020
Merged
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: 7 additions & 5 deletions snowpack/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1145,29 +1145,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