🔨 Add 'User-Agent'in 'SetDefaults' function

This commit is contained in:
2025-03-22 22:25:54 +04:00
parent 11bb8b3fb0
commit 2a0ac390d8
4 changed files with 19 additions and 4 deletions

View File

@@ -73,6 +73,15 @@ func (headers Headers) GetValue(key string) *[]string {
return nil
}
func (headers Headers) Has(key string) bool {
for i := range headers {
if headers[i].Key == key {
return true
}
}
return false
}
func (headers *Headers) UnmarshalJSON(b []byte) error {
var data []map[string]any
if err := json.Unmarshal(b, &data); err != nil {
@@ -137,3 +146,11 @@ func (headers *Headers) Set(value string) error {
return nil
}
func (headers *Headers) SetIfNotExists(key string, value string) bool {
if headers.Has(key) {
return false
}
*headers = append(*headers, KeyValue[string, []string]{Key: key, Value: []string{value}})
return true
}