Skip to content

go-http-utils/fresh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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