github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/http/header-content-length.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package http 4 5 import "strconv" 6 7 // ContentLength read all value about content in header 8 func (h *header) ContentLength() (l uint64) { 9 var contentLength = h.Get(HeaderKeyContentLength) 10 l, _ = strconv.ParseUint(contentLength, 10, 64) 11 return 12 } 13 14 // SetContentLength set body length to header 15 func (h *header) SetContentLength(bodyLength uint64) { 16 h.Set(HeaderKeyContentLength, strconv.FormatUint(bodyLength, 10)) 17 } 18 19 // SetZeroContentLength set body length to header 20 func (h *header) SetZeroContentLength() { 21 h.Set(HeaderKeyContentLength, "0") 22 } 23 24 // SetContentLength set body length to header. 25 func (r *Request) SetContentLength() { 26 r.H.Set(HeaderKeyContentLength, strconv.FormatUint(uint64(r.body.Len()), 10)) 27 } 28 29 // SetContentLength set body length to header. 30 func (r *Response) SetContentLength() { 31 r.H.Set(HeaderKeyContentLength, strconv.FormatUint(uint64(r.body.Len()), 10)) 32 }