This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cache-control): add cache control handler (#13)
* add cache control * feat(cache-control): add cache control handler * chore(cache-control): remove unused function * fix(expiry): add condition for expired response * chore(example): add example how to use
- Loading branch information
Showing
13 changed files
with
1,316 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package control | ||
|
||
import ( | ||
// "github.com/pquerna/cachecontrol/cacheobject" | ||
cacheobject "github.com/bxcodec/hache/control/cacheheader" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
type Options struct { | ||
// Set to True for a prviate cache, which is not shared amoung users (eg, in a browser) | ||
// Set to False for a "shared" cache, which is more common in a server context. | ||
PrivateCache bool | ||
} | ||
|
||
// Given an HTTP Request, the future Status Code, and an ResponseWriter, | ||
// determine the possible reasons a response SHOULD NOT be cached. | ||
func CachableResponseWriter(req *http.Request, | ||
statusCode int, | ||
resp http.ResponseWriter, | ||
opts Options) ([]cacheobject.Reason, time.Time, error) { | ||
return cacheobject.UsingRequestResponse(req, statusCode, resp.Header(), opts.PrivateCache) | ||
} | ||
|
||
// Given an HTTP Request and Response, determine the possible reasons a response SHOULD NOT | ||
// be cached. | ||
func CachableResponse(req *http.Request, | ||
resp *http.Response, | ||
opts Options) ([]cacheobject.Reason, time.Time, error) { | ||
return cacheobject.UsingRequestResponse(req, resp.StatusCode, resp.Header, opts.PrivateCache) | ||
} |
Oops, something went wrong.