HTTP response freshness testing for Go
go get -u github.com/go-http-utils/fresh
API documentation can be found here: https://godoc.org/github.com/go-http-utils/fresh
import (
"net/http"
"github.com/go-http-utils/fresh"
"github.com/go-http-utils/headers"
)
reqHeader, resHeader := make(http.Header), make(http.Header)
reqHeader.Set(headers.IfNoneMatch, "foo")
resHeader.Set(headers.ETag, "bar")
fresh.IsFresh(reqHeader, resHeader)
// -> false
reqHeader, resHeader := make(http.Header), make(http.Header)
reqHeader.Set(headers.IfMatch, "foo")
resHeader.Set(headers.ETag, "bar")
fresh.IsFresh(reqHeader, resHeader)
// -> true
reqHeader, resHeader := make(http.Header), make(http.Header)
reqHeader.Set(headers.IfModifiedSince, "Mon, 14 Nov 2016 22:05:49 GMT")
resHeader.Set(headers.LastModified, "Mon, 14 Nov 2016 22:05:47 GMT")
fresh.IsFresh(reqHeader, resHeader)
// -> true
reqHeader, resHeader := make(http.Header), make(http.Header)
resHeader.Set(headers.IfUnmodifiedSince, "Mon, 14 Nov 2016 22:05:47 GMT")
reqHeader.Set(headers.LastModified, "Mon, 14 Nov 2016 22:05:49 GMT")
fresh.IsFresh(reqHeader, resHeader)
// -> true