Clear the etag header to force Express to regenerate the etag as body may have changed. This prevents 304 Not Modified when downstream response is unchanged but userResDecorator has.
Background
We found an issue in our live deployment where the client was using stale cached responses. The issue was the downstream web server responding with an etag header based on it's response body which was unchanged.
express-http-proxy proxies this etag header back to the client even when userResDecorator may have changed the response. In our scenario the amendment to the response is itself dynamic.
The fix was straightforward but I thought this gotcha could be affecting many people without their knowledge.
Workaround without changing express-http-proxy
const ResetEtagHeader = (headers: IncomingHttpHeaders): OutgoingHttpHeaders => {
// Clear the etag header so Express will regenerate it
headers.etag = '';
return headers;
};
proxy(serverURL, {
userResDecorator: DynamicDecoratorBlah,
userResHeaderDecorator: ResetEtagHeader,
});
Change
Clear the etag header to force Express to regenerate the etag as body may have changed. This prevents 304 Not Modified when downstream response is unchanged but userResDecorator has.
Background
We found an issue in our live deployment where the client was using stale cached responses. The issue was the downstream web server responding with an
etag
header based on it's response body which was unchanged.express-http-proxy
proxies thisetag
header back to the client even whenuserResDecorator
may have changed the response. In our scenario the amendment to the response is itself dynamic.The fix was straightforward but I thought this gotcha could be affecting many people without their knowledge.
Workaround without changing
express-http-proxy