Issue #83: Added ResponseHeader.DelClientCookie for instructing the client for removing the given cookie. Clarified ResponseHeader.DelCookie documentations

This commit is contained in:
Aliaksandr Valialkin
2016-04-29 14:40:55 +03:00
parent 0f76772285
commit 3509bd8a7d
2 changed files with 50 additions and 2 deletions
+28 -2
View File
@@ -944,12 +944,38 @@ func (h *RequestHeader) SetCookieBytesKV(key, value []byte) {
h.SetCookie(b2s(key), b2s(value))
}
// DelCookie removes cookie under the given key.
// DelClientCookie instructs the client to remove the given cookie.
//
// Use DelCookie if you want just removing the cookie from response header.
func (h *ResponseHeader) DelClientCookie(key string) {
h.DelCookie(key)
c := AcquireCookie()
c.SetKey(key)
c.SetExpire(CookieExpireDelete)
h.SetCookie(c)
ReleaseCookie(c)
}
// DelClientCookieBytes instructs the client to remove the given cookie.
//
// Use DelCookieBytes if you want just removing the cookie from response header.
func (h *ResponseHeader) DelClientCookieBytes(key []byte) {
h.DelClientCookie(b2s(key))
}
// DelCookie removes cookie under the given key from response header.
//
// Note that DelCookie doesn't remove the cookie from the client.
// Use DelClientCookie instead.
func (h *ResponseHeader) DelCookie(key string) {
h.cookies = delAllArgs(h.cookies, key)
}
// DelCookieBytes removes cookie under the given key.
// DelCookieBytes removes cookie under the given key from response header.
//
// Note that DelCookieBytes doesn't remove the cookie from the client.
// Use DelClientCookieBytes instead.
func (h *ResponseHeader) DelCookieBytes(key []byte) {
h.DelCookie(b2s(key))
}
+22
View File
@@ -10,6 +10,28 @@ import (
"testing"
)
func TestResponseHeaderDelClientCookie(t *testing.T) {
cookieName := "foobar"
var h ResponseHeader
c := AcquireCookie()
c.SetKey(cookieName)
c.SetValue("aasdfsdaf")
h.SetCookie(c)
h.DelClientCookieBytes([]byte(cookieName))
if !h.Cookie(c) {
t.Fatalf("expecting cookie %q", c.Key())
}
if !c.Expire().Equal(CookieExpireDelete) {
t.Fatalf("unexpected cookie expiration time: %s. Expecting %s", c.Expire(), CookieExpireDelete)
}
if len(c.Value()) > 0 {
t.Fatalf("unexpected cookie value: %q. Expecting empty value", c.Value())
}
ReleaseCookie(c)
}
func TestResponseHeaderAdd(t *testing.T) {
m := make(map[string]struct{})
var h ResponseHeader