adc06
adc06

Reputation: 793

How to use Etag with sailsjs

I'm trying to improve the cache capabilities on my sails application.

Sails generate a Etag with its response but when I try to do a GET request with a header 'if-None-Match' containing the Etag from the previous answer I can't get a 304 not Modified response from the server (the response is indeed not Modified and the Etag I receive is the same as the previous one).

I'm using POSTMAN to test the server responses.

Is there a way for a sails server to send such status code on unmodified responses ? I can't find any resource for Etag usage in sails doc.

Thank you.

Upvotes: 1

Views: 779

Answers (1)

Ryan W
Ryan W

Reputation: 6173

Sails.js is based on Express.js and the ETags are generated by Express.js. And according to this answer, weak ETags are generated using CRC32 (source), strong ETags are generated using MD5 (source).

I use DHC - REST/HTTP API Client with If-None-Match header, it works perfect (return 304 Not Modified).

And I found that's because POSTMAN send NO-CACHE header to the server for testing purpose

'cache-control': 'no-cache',

You can follow this answer and turn off this feature then everything will be fine.

Upvotes: 0

Related Questions