当前位置: 首页>>代码示例>>Golang>>正文


Golang Header.Del方法代码示例

本文整理汇总了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
}
开发者ID:y-yagi,项目名称:puma-dev,代码行数:35,代码来源:transfer.go

示例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
}
开发者ID:fdr,项目名称:roundtripper,代码行数:27,代码来源:transfer.go

示例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)
		}
	}
}
开发者ID:uriel,项目名称:goproxy,代码行数:10,代码来源:proxy.go

示例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
}
开发者ID:Comcast,项目名称:golang-money,代码行数:11,代码来源:httpConn.go

示例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)
		}
	}
}
开发者ID:netxfly,项目名称:Transparent-Proxy-Scanner,代码行数:12,代码来源:main.go

示例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
	}
}
开发者ID:keis,项目名称:docker-ec2-metadata,代码行数:11,代码来源:main.go

示例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
}
开发者ID:russellsimpkins,项目名称:ensemble,代码行数:15,代码来源:service.go

示例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))
}
开发者ID:na--,项目名称:nedomi,代码行数:13,代码来源:flv.go

示例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]))
		}
	}
}
开发者ID:FiloSottile,项目名称:caddy,代码行数:13,代码来源:proxy.go

示例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)
	}
}
开发者ID:na--,项目名称:nedomi,代码行数:13,代码来源:header_rewrite.go

示例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)
	}
}
开发者ID:shawnps,项目名称:martian,代码行数:14,代码来源:hopbyhop_modifier.go

示例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
}
开发者ID:fdr,项目名称:roundtripper,代码行数:52,代码来源:transfer.go

示例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{})
	}
}
开发者ID:mbentley,项目名称:notary,代码行数:16,代码来源:http.go

示例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)
	}
}
开发者ID:yyhaoyue,项目名称:gopee,代码行数:15,代码来源:gopee.go

示例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)
		}
	}
}
开发者ID:Makpoc,项目名称:caddy,代码行数:16,代码来源:reverseproxy.go


注:本文中的net/http.Header.Del方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。