-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30322c9
commit 53b6612
Showing
4 changed files
with
92 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Package fresh is used to check whether cache can be used in this HTTP request. | ||
// | ||
// ---------------------------------------------------------------- | ||
// | ||
// reqHeader, resHeader := make(http.Header), make(http.Header) | ||
// | ||
// reqHeader.Set("if-none-match", "foo") | ||
// resHeader.Set("etag", "bar") | ||
|
||
// fresh.IsFresh(reqHeader, resHeader) | ||
// // -> false | ||
// | ||
// ---------------------------------------------------------------- | ||
// | ||
// reqHeader, resHeader := make(http.Header), make(http.Header) | ||
|
||
// reqHeader.Set("if-modified-since", "Mon, 14 Nov 2016 22:05:49 GMT") | ||
// resHeader.Set("last-modified", "Mon, 14 Nov 2016 22:05:47 GMT") | ||
|
||
// fresh.IsFresh(reqHeader, resHeader) | ||
// // -> true | ||
// | ||
// ---------------------------------------------------------------- | ||
|
||
package fresh |
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,26 @@ | ||
package fresh_test | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/go-http-utils/fresh" | ||
) | ||
|
||
func ExampleFresh_IsFresh() { | ||
reqHeader, resHeader := make(http.Header), make(http.Header) | ||
|
||
reqHeader.Set("if-none-match", "foo") | ||
resHeader.Set("etag", "bar") | ||
|
||
fmt.Println(fresh.IsFresh(reqHeader, resHeader)) | ||
// -> false | ||
|
||
reqHeader, resHeader = make(http.Header), make(http.Header) | ||
|
||
reqHeader.Set("if-modified-since", "Mon, 14 Nov 2016 22:05:49 GMT") | ||
resHeader.Set("last-modified", "Mon, 14 Nov 2016 22:05:47 GMT") | ||
|
||
fmt.Println(fresh.IsFresh(reqHeader, resHeader)) | ||
// -> true | ||
} |
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