aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/http/header.go
diff options
context:
space:
mode:
authorPetar Maymounkov <petarm@gmail.com>2011-02-23 00:39:25 -0500
committerRuss Cox <rsc@golang.org>2011-02-23 00:39:25 -0500
commitb8fa61885ad076081a42231ae50fe374dceff500 (patch)
tree12562bd386c93f8bf22c71f3927a67d2449320d3 /src/pkg/http/header.go
parent07cc8b9ad21a164a64139de169e8eceb1f90c61a (diff)
downloadgo-b8fa61885ad076081a42231ae50fe374dceff500.tar.xz
http: introduce Header type, implement with net/textproto
textproto: introduce Header type websocket: use new interface to access Header R=rsc, mattn CC=golang-dev https://golang.org/cl/4185053
Diffstat (limited to 'src/pkg/http/header.go')
-rw-r--r--src/pkg/http/header.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/pkg/http/header.go b/src/pkg/http/header.go
new file mode 100644
index 0000000000..95b0f3db6b
--- /dev/null
+++ b/src/pkg/http/header.go
@@ -0,0 +1,43 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package http
+
+import "net/textproto"
+
+// A Header represents the key-value pairs in an HTTP header.
+type Header map[string][]string
+
+// Add adds the key, value pair to the header.
+// It appends to any existing values associated with key.
+func (h Header) Add(key, value string) {
+ textproto.MIMEHeader(h).Add(key, value)
+}
+
+// Set sets the header entries associated with key to
+// the single element value. It replaces any existing
+// values associated with key.
+func (h Header) Set(key, value string) {
+ textproto.MIMEHeader(h).Set(key, value)
+}
+
+// Get gets the first value associated with the given key.
+// If there are no values associated with the key, Get returns "".
+// Get is a convenience method. For more complex queries,
+// access the map directly.
+func (h Header) Get(key string) string {
+ return textproto.MIMEHeader(h).Get(key)
+}
+
+// Del deletes the values associated with key.
+func (h Header) Del(key string) {
+ textproto.MIMEHeader(h).Del(key)
+}
+
+// CanonicalHeaderKey returns the canonical format of the
+// header key s. The canonicalization converts the first
+// letter and any letter following a hyphen to upper case;
+// the rest are converted to lowercase. For example, the
+// canonical key for "accept-encoding" is "Accept-Encoding".
+func CanonicalHeaderKey(s string) string { return textproto.CanonicalMIMEHeaderKey(s) }