Skip to content

Latest commit

 

History

History
66 lines (46 loc) · 1.51 KB

README.md

File metadata and controls

66 lines (46 loc) · 1.51 KB

fresh

Build Status Coverage Status

HTTP response freshness testing for Go

Installation

go get -u github.com/go-http-utils/fresh

Documentation

API documentation can be found here: https://godoc.org/github.com/go-http-utils/fresh

Usage

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