Implement statusCodeFilter option for client #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation 1: my project that uses this library takes a rather long time to generate responses with status codes 404 and 503. It would be much more efficient to cache those responses, but the library just ignores responses with status codes >= 400 (this is hardcoded).
Motivation 2: status codes of responses served from cache are always 200, which seems like a bug. Response status codes may bring important information that API clients may rely upon. Replacing them all with 200 essentially destroys this information.
Changes 1: this PR implements status code filter option. It allows users to control responses with which status codes should be cached. If the option is not specified, everything below 400 will be cached, just like before, so it's 100% backward compatible.
Changes 2: This PR makes it so that status codes from original responses get saved in cache and reused later when served from it. This might not be backward compatible in some very specific use cases.
Example: this is a snippet of how I'd like to use this option in my project. It will cache all responses with status codes above and below 400, but not 400 (400 is used for format validation errors and can be generated quickly, so there's no need for me to cache it):