Fix: Prevent If-None-Match and If-Modified-Since headers when override is true

Co-authored-by: arthurfiorette <47537704+arthurfiorette@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-08 13:24:10 +00:00
parent da02a9f6d4
commit 23cdaa2350
3 changed files with 56 additions and 1 deletions

View File

@ -182,7 +182,7 @@ export function defaultRequestInterceptor(axios: AxiosCacheInstance): RequestInt
config config
); );
if (cache.state === 'stale' || cache.state === 'must-revalidate') { if ((cache.state === 'stale' || cache.state === 'must-revalidate') && !overrideCache) {
updateStaleRequest(cache, config as ConfigWithCache<unknown>); updateStaleRequest(cache, config as ConfigWithCache<unknown>);
if (__ACI_DEV__) { if (__ACI_DEV__) {

View File

@ -87,4 +87,26 @@ describe('ETag handling', () => {
assert.equal(response2.config.headers?.[Header.IfNoneMatch], 'fake-etag'); assert.equal(response2.config.headers?.[Header.IfNoneMatch], 'fake-etag');
assert.equal(response2.headers?.[Header.ETag], 'fake-etag-2'); assert.equal(response2.headers?.[Header.ETag], 'fake-etag-2');
}); });
it('No If-None-Match header when override is true', async () => {
const axios = mockAxios({}, { etag: 'fakeEtag', 'cache-control': 'max-age=1' });
const config = { cache: { interpretHeader: true, etag: true } };
// Initial request to populate cache
const response1 = await axios.get('http://test.com', config);
assert.equal(response1.cached, false);
assert.equal(response1.status, 200);
// Sleep to make cache stale
await mockDateNow(1000);
// Request with override should not send If-None-Match and should get 200, not 304
const response2 = await axios.get('http://test.com', {
cache: { ...config.cache, override: true }
});
assert.equal(response2.cached, false);
assert.equal(response2.stale, undefined);
assert.equal(response2.status, 200); // Should be 200, not 304
assert.equal(response2.config.headers?.[Header.IfNoneMatch], undefined);
});
}); });

View File

@ -135,4 +135,37 @@ describe('LastModified handling', () => {
assert.notEqual(Number(secondMyHeader), Number.NaN); assert.notEqual(Number(secondMyHeader), Number.NaN);
assert.notEqual(secondMyHeader, firstMyHeader); assert.notEqual(secondMyHeader, firstMyHeader);
}); });
it('No If-Modified-Since header when override is true', async () => {
const axios = mockAxios(
{},
{
'last-modified': 'Wed, 21 Oct 2015 07:28:00 GMT',
'cache-control': 'max-age=1'
}
);
const config: CacheRequestConfig = {
id: 'same request',
cache: { interpretHeader: true, modifiedSince: true }
};
// Initial request to populate cache
const response1 = await axios.get('url', config);
assert.equal(response1.cached, false);
assert.equal(response1.status, 200);
// Sleep to make cache stale
await mockDateNow(1000);
// Request with override should not send If-Modified-Since and should get 200, not 304
const response2 = await axios.get('url', {
...config,
cache: { ...config.cache, override: true }
});
assert.equal(response2.cached, false);
assert.equal(response2.stale, undefined);
assert.equal(response2.status, 200); // Should be 200, not 304
assert.equal(response2.config.headers?.[Header.IfModifiedSince], undefined);
});
}); });