Skip to content

Commit

Permalink
only generate etags for responses that dont have them already
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jan 15, 2022
1 parent d464057 commit c054545
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/kit/src/runtime/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ export async function respond(incoming, options, state = {}) {
: await render_page(request, route, match, options, state, ssr);

if (response) {
// inject ETags for 200 responses
if (response.status === 200) {
// inject ETags for 200 responses, if the endpoint
// doesn't have its own ETag handling
if (response.status === 200 && !response.headers.etag) {
const cache_control = get_single_valued_header(response.headers, 'cache-control');
if (!cache_control || !/(no-store|immutable)/.test(cache_control)) {
let if_none_match_value = request.headers['if-none-match'];
Expand Down Expand Up @@ -157,9 +158,7 @@ export async function respond(incoming, options, state = {}) {
};
}

if (!response.headers['etag']) {
response.headers['etag'] = etag;
}
response.headers['etag'] = etag;
}
}

Expand Down

0 comments on commit c054545

Please sign in to comment.