Here we go again...

This commit is contained in:
2025-08-28 21:25:10 +04:00
parent 25d4762a3c
commit 42335c1178
62 changed files with 4579 additions and 4460 deletions

52
pkg/types/header.go Normal file
View File

@@ -0,0 +1,52 @@
package types
import "strings"
type Header KeyValue[string, []string]
type Headers []Header
// Has checks if a header with the given key exists.
func (headers Headers) Has(key string) bool {
for i := range headers {
if headers[i].Key == key {
return true
}
}
return false
}
func (headers Headers) GetValue(key string) *[]string {
for i := range headers {
if headers[i].Key == key {
return &headers[i].Value
}
}
return nil
}
func (headers *Headers) Append(header Header) {
if item := headers.GetValue(header.Key); item != nil {
*item = append(*item, header.Value...)
} else {
*headers = append(*headers, header)
}
}
func (headers *Headers) Parse(rawValues ...string) {
for _, rawValue := range rawValues {
headers.Append(*ParseHeader(rawValue))
}
}
func ParseHeader(rawValue string) *Header {
parts := strings.SplitN(rawValue, ": ", 2)
switch len(parts) {
case 1:
return &Header{Key: parts[0], Value: []string{""}}
case 2:
return &Header{Key: parts[0], Value: []string{parts[1]}}
default:
return &Header{Key: "", Value: []string{""}}
}
}