本文整理汇总了Golang中net/http.Header.Del方法的典型用法代码示例。如果您正苦于以下问题:Golang Header.Del方法的具体用法?Golang Header.Del怎么用?Golang Header.Del使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net/http.Header
的用法示例。
在下文中一共展示了Header.Del方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: fixTrailer
// Parse the trailer header
func fixTrailer(header http.Header, te []string) (http.Header, error) {
vv, ok := header["Trailer"]
if !ok {
return nil, nil
}
header.Del("Trailer")
trailer := make(http.Header)
var err error
for _, v := range vv {
foreachHeaderElement(v, func(key string) {
key = http.CanonicalHeaderKey(key)
switch key {
case "Transfer-Encoding", "Trailer", "Content-Length":
if err == nil {
err = fmt.Errorf("bad trailer key: %s", key)
return
}
}
trailer[key] = nil
})
}
if err != nil {
return nil, err
}
if len(trailer) == 0 {
return nil, nil
}
if !chunked(te) {
// Trailer and no chunking
return nil, http.ErrUnexpectedTrailer
}
return trailer, nil
}
示例2: fixTrailer
// Parse the trailer header
func fixTrailer(header http.Header, te []string) (http.Header, error) {
raw := get(header, "Trailer")
if raw == "" {
return nil, nil
}
header.Del("Trailer")
trailer := make(http.Header)
keys := strings.Split(raw, ",")
for _, key := range keys {
key = http.CanonicalHeaderKey(strings.TrimSpace(key))
switch key {
case "Transfer-Encoding", "Trailer", "Content-Length":
return nil, &badStringError{"bad trailer key", key}
}
trailer.Del(key)
}
if len(trailer) == 0 {
return nil, nil
}
if !chunked(te) {
// Trailer and no chunking
return nil, http.ErrUnexpectedTrailer
}
return trailer, nil
}
示例3: copyHeaders
func copyHeaders(dst, src http.Header) {
for k, _ := range dst {
dst.Del(k)
}
for k, vs := range src {
for _, v := range vs {
dst.Add(k, v)
}
}
}
示例4: DelAllMNYHeaders
// Removes the Money header from the http.Header
func DelAllMNYHeaders(header http.Header) http.Header {
for h := range header {
if strings.EqualFold(h, HEADER) {
header.Del(h)
return header
}
}
return header
}
示例5: copyHeader
// copyHeader copies headers from one http.Header to another.
// http://golang.org/src/pkg/net/http/httputil/reverseproxy.go#L72
func copyHeader(dst http.Header, src http.Header) {
for k := range dst {
dst.Del(k)
}
for k, vv := range src {
for _, v := range vv {
dst.Add(k, v)
}
}
}
示例6: copyHeaders
func copyHeaders(dst, src http.Header) {
for k, _ := range dst {
dst.Del(k)
}
for k, v := range src {
vCopy := make([]string, len(v))
copy(vCopy, v)
dst[k] = vCopy
}
}
示例7: replaceHeaderValues
// logic to replace header values in the target with those in the source
// this leaves any header values in the target that aren't in the source
// if you wanted that, don't call this fuction.
func replaceHeaderValues(target *http.Header, source *http.Header) {
if target == nil {
target = new(http.Header)
}
for name, vals := range *source {
target.Del(name)
for _, val := range vals {
target.Add(name, val)
}
}
return
}
示例8: recalculateContentLength
func recalculateContentLength(header http.Header) {
var contentLengthStr = header.Get("Content-Length")
if contentLengthStr == "" {
return
}
var contentLength, err = strconv.Atoi(contentLengthStr)
if err != nil {
header.Del("Content-Length")
return
}
contentLength += len(flvHeader)
header.Set("Content-Length", strconv.Itoa(contentLength))
}
示例9: mutateHeadersByRules
func mutateHeadersByRules(headers, rules http.Header, repl httpserver.Replacer) {
for ruleField, ruleValues := range rules {
if strings.HasPrefix(ruleField, "+") {
for _, ruleValue := range ruleValues {
headers.Add(strings.TrimPrefix(ruleField, "+"), repl.Replace(ruleValue))
}
} else if strings.HasPrefix(ruleField, "-") {
headers.Del(strings.TrimPrefix(ruleField, "-"))
} else if len(ruleValues) > 0 {
headers.Set(ruleField, repl.Replace(ruleValues[len(ruleValues)-1]))
}
}
}
示例10: rewrite
func (hr *headersRewrite) rewrite(headers http.Header) {
for _, key := range hr.RemoveHeaders {
headers.Del(key)
}
for key, values := range hr.AddHeaders {
addValues(headers, key, values)
}
for key, values := range hr.SetHeaders {
headers.Del(key)
addValues(headers, key, values)
}
}
示例11: removeHopByHopHeaders
func removeHopByHopHeaders(header http.Header) {
// Additional hop-by-hop headers may be specified in `Connection` headers.
// http://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-14#section-9.1
for _, vs := range header["Connection"] {
for _, v := range strings.Split(vs, ",") {
k := http.CanonicalHeaderKey(strings.TrimSpace(v))
header.Del(k)
}
}
for _, k := range HopByHopHeaders {
header.Del(k)
}
}
示例12: fixLength
// Determine the expected body length, using RFC 2616 Section 4.4. This
// function is not a method, because ultimately it should be shared by
// ReadResponse and ReadRequest.
func fixLength(isResponse bool, status int, requestMethod string, header http.Header, te []string) (int64, error) {
// Logic based on response type or status
if noBodyExpected(requestMethod) {
return 0, nil
}
if status/100 == 1 {
return 0, nil
}
switch status {
case 204, 304:
return 0, nil
}
// Logic based on Transfer-Encoding
if chunked(te) {
return -1, nil
}
// Logic based on Content-Length
cl := strings.TrimSpace(get(header, "Content-Length"))
if cl != "" {
n, err := strconv.ParseInt(cl, 10, 64)
if err != nil || n < 0 {
return -1, &badStringError{"bad Content-Length", cl}
}
return n, nil
} else {
header.Del("Content-Length")
}
if !isResponse && requestMethod == "GET" {
// RFC 2616 doesn't explicitly permit nor forbid an
// entity-body on a GET request so we permit one if
// declared, but we default to 0 here (not -1 below)
// if there's no mention of a body.
return 0, nil
}
// Logic based on media type. The purpose of the following code is just
// to detect whether the unsupported "multipart/byteranges" is being
// used. A proper Content-Type parser is needed in the future.
if strings.Contains(strings.ToLower(get(header, "Content-Type")), "multipart/byteranges") {
return -1, http.ErrNotSupported
}
// Body-EOF logic based on other methods (like closing, or chunked coding)
return -1, nil
}
示例13: SetHeaders
// SetHeaders sets the public headers with an optional must-revalidate header
func (p PublicCacheControl) SetHeaders(headers http.Header) {
cacheControlValue := fmt.Sprintf("public, max-age=%v, s-maxage=%v",
p.MaxAgeInSeconds, p.MaxAgeInSeconds)
if p.MustReValidate {
cacheControlValue = fmt.Sprintf("%s, must-revalidate", cacheControlValue)
}
headers.Set("Cache-Control", cacheControlValue)
// delete the Pragma directive, because the only valid value in HTTP is
// "no-cache"
headers.Del("Pragma")
if headers.Get("Last-Modified") == "" {
SetLastModifiedHeader(headers, time.Time{})
}
}
示例14: copyHeader
func copyHeader(dst, src http.Header) {
// Copy Headers from src to dst
for k, vv := range src {
for _, v := range vv {
dst.Add(k, v)
}
}
// Remove hop-by-hop headers and problem headers
for h, _ := range hopHeaders {
dst.Del(h)
}
for h, _ := range skipHeaders {
dst.Del(h)
}
}
示例15: copyHeader
func copyHeader(dst, src http.Header) {
for k, vv := range src {
if _, ok := dst[k]; ok {
// skip some predefined headers
// see https://github.com/mholt/caddy/issues/1086
if _, shouldSkip := skipHeaders[k]; shouldSkip {
continue
}
// otherwise, overwrite
dst.Del(k)
}
for _, v := range vv {
dst.Add(k, v)
}
}
}