github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/http/header-content-encoding.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package http 4 5 import "strings" 6 7 type ContentEncodings string 8 9 func (c ContentEncodings) Next() (contentEncoding string, remain ContentEncodings) { 10 var commaIndex int = strings.IndexByte(string(c), Comma) 11 if commaIndex == -1 { 12 commaIndex = len(c) 13 } else { 14 remain = c[commaIndex+1:] 15 } 16 contentEncoding = string(c[:commaIndex]) 17 return 18 } 19 20 // ContentEncoding return content encoding and notify if multiple exist 21 // To read multiple just call this method in a loop to get multiple became false 22 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding 23 func (h *header) ContentEncoding() (ce string, multiple bool) { 24 var contentEncoding = h.Get(HeaderKeyContentEncoding) 25 var commaIndex int = strings.IndexByte(contentEncoding, Comma) 26 if commaIndex == -1 { 27 commaIndex = len(contentEncoding) 28 } else { 29 h.Replace(HeaderKeyContentEncoding, contentEncoding[commaIndex+1:]) 30 multiple = true 31 } 32 ce = contentEncoding[:commaIndex] 33 return 34 } 35 36 func (h *header) SetContentEncoding(contentEncodings ...string) { 37 h.Sets(HeaderKeyContentEncoding, contentEncodings) 38 }