Skip to content
Switch branches/tags
Go to file
Set the returned http.Cookie's SameSite field to the value of the
SameSite field in the Options struct passed into NewCookie.  This
fixes an oversight made in PR #165 which was made to address issue

Add a newCookieFromOptions function which takes a name, value and
Options struct and returns an http.Cookie.  There are two
newCookieFromOptions implementations, one for Go 1.11 and later which
sets SameSite and one for earlier Go versions which does not.

Add new tests TestNewCookieFromOptions and
TestNewCookieFromOptionsSameSite which ensure that the values passed
to newCookieFromOptions are properly set in the returned cookie.  The
test TestNewCookieFromOptionsSameSite only runs if running Go 1.11 and
1 contributor

Users who have contributed to this file

// +build !go1.11
package sessions
import "net/http"
// newCookieFromOptions returns an http.Cookie with the options set.
func newCookieFromOptions(name, value string, options *Options) *http.Cookie {
return &http.Cookie{
Name: name,
Value: value,
Path: options.Path,
Domain: options.Domain,
MaxAge: options.MaxAge,
Secure: options.Secure,
HttpOnly: options.HttpOnly,