mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-16 09:53:12 +00:00
Merge pull request #100 from aykhans/refactor/config
All checks were successful
golangci-lint / lint (push) Successful in 25s
All checks were successful
golangci-lint / lint (push) Successful in 25s
🔨 Add 'User-Agent' in 'SetDefaults' function
This commit is contained in:
commit
a170588574
@ -45,7 +45,7 @@ Flags:
|
|||||||
-m, -method string HTTP Method for the request (default %s)
|
-m, -method string HTTP Method for the request (default %s)
|
||||||
-b, -body [string] Body for the request (e.g. "body text")
|
-b, -body [string] Body for the request (e.g. "body text")
|
||||||
-p, -param [string] Parameter for the request (e.g. "key1=value1")
|
-p, -param [string] Parameter for the request (e.g. "key1=value1")
|
||||||
-H, -header [string] Header for the request (e.g. "key1: value1")
|
-H, -header [string] Header for the request (e.g. "key1:value1")
|
||||||
-c, -cookie [string] Cookie for the request (e.g. "key1=value1")
|
-c, -cookie [string] Cookie for the request (e.g. "key1=value1")
|
||||||
-x, -proxy [string] Proxy for the request (e.g. "http://proxy.example.com:8080")`
|
-x, -proxy [string] Proxy for the request (e.g. "http://proxy.example.com:8080")`
|
||||||
|
|
||||||
|
@ -233,4 +233,5 @@ func (config *Config) SetDefaults() {
|
|||||||
if config.Yes == nil {
|
if config.Yes == nil {
|
||||||
config.Yes = utils.ToPtr(DefaultYes)
|
config.Yes = utils.ToPtr(DefaultYes)
|
||||||
}
|
}
|
||||||
|
config.Headers.SetIfNotExists("User-Agent", DefaultUserAgent)
|
||||||
}
|
}
|
||||||
|
@ -166,9 +166,6 @@ func setRequestHeaders(req *fasthttp.Request, headers []types.KeyValue[string, s
|
|||||||
for _, header := range headers {
|
for _, header := range headers {
|
||||||
req.Header.Add(header.Key, header.Value)
|
req.Header.Add(header.Key, header.Value)
|
||||||
}
|
}
|
||||||
if req.Header.UserAgent() == nil {
|
|
||||||
req.Header.SetUserAgent(config.DefaultUserAgent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setRequestCookies adds the cookies of the given request with the provided key-value pairs.
|
// setRequestCookies adds the cookies of the given request with the provided key-value pairs.
|
||||||
|
@ -73,6 +73,15 @@ func (headers Headers) GetValue(key string) *[]string {
|
|||||||
return nil
|
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 {
|
func (headers *Headers) UnmarshalJSON(b []byte) error {
|
||||||
var data []map[string]any
|
var data []map[string]any
|
||||||
if err := json.Unmarshal(b, &data); err != nil {
|
if err := json.Unmarshal(b, &data); err != nil {
|
||||||
@ -137,3 +146,11 @@ func (headers *Headers) Set(value string) error {
|
|||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user