package httpimport ()func ( []string, func(string) ([]string, error)) ([]string, error) { := make([]string, 0, len())for := 0; < len(); ++ { , := ([])if != nil {returnnil, } = append(, ...) }return , nil}// SplitHeaderListValues attempts to split the elements of the slice by commas,// and return a list of all values separated. Returns error if unable to// separate the values.func ( []string) ([]string, error) {returnsplitHeaderListValues(, quotedCommaSplit)}func ( string) ( []string, error) { = strings.TrimSpace() := truefor := 0; < len(); ++ {ifunicode.IsSpace(rune([])) {continue } = false// leading space in part is ignored. // Start of value must be non-space, or quote. // // - If quote, enter quoted mode, find next non-escaped quote to // terminate the value. // - Otherwise, find next comma to terminate value. := [:]varstringvarintif [0] == '"' {//------------------------------ // Quoted value //------------------------------varintvarboolfor += 1; < len(); ++ {if [] == '\\' || ([] != '\\' && ) { = !continue }if [] == '"' {break } }if == len() || == 1 {returnnil, fmt.Errorf("value %v missing closing double quote", ) } = + 1 := [:]varintfor ; < len(); ++ {if !unicode.IsSpace(rune([])) && [] != ',' {returnnil, fmt.Errorf("value %v has non-space trailing characters", ) }if [] == ',' { = truebreak } } = [:] , = strconv.Unquote()if != nil {returnnil, fmt.Errorf("failed to unquote value %v, %w", , ) }// Pad valueLen to include trailing space(s) so `i` is updated correctly. += } else {//------------------------------ // Unquoted value //------------------------------// Index of the next comma is the length of the value, or end of string. = strings.Index(, ",")if != -1 { = true } else { = len() } = strings.TrimSpace([:]) } += = append(, ) }if { = append(, "") }return , nil}// SplitHTTPDateTimestampHeaderListValues attempts to split the HTTP-Date// timestamp values in the slice by commas, and return a list of all values// separated. The split is aware of the HTTP-Date timestamp format, and will skip// comma within the timestamp value. Returns an error if unable to split the// timestamp values.func ( []string) ([]string, error) {returnsplitHeaderListValues(, splitHTTPDateHeaderValue)}func ( string) ([]string, error) {if := strings.Count(, ","); <= 1 {// Nothing to do if only contains a no, or single HTTPDate valuereturn []string{}, nil } elseif %2 == 0 {returnnil, fmt.Errorf("invalid timestamp HTTPDate header comma separations, %q", ) }var []stringvar , intvarboolfor ; < len(); ++ {if [] == ',' {if { = false = append(, strings.TrimSpace([:])) = + 1 } else {// Skip the first comma in the timestamp value since that // separates the day from the rest of the timestamp. // // Tue, 17 Dec 2019 23:48:18 GMT = true } } }// Add final partif < len() { = append(, strings.TrimSpace([:])) }return , nil}
The pages are generated with Goldsv0.4.9. (GOOS=linux GOARCH=amd64)