net.http: use `[params]` for Config structs (#12299)
parent
06796a6119
commit
655b5c563a
|
@ -432,17 +432,16 @@ pub fn (mut h Header) delete_custom(key string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[params]
|
||||||
pub struct HeaderCoerceConfig {
|
pub struct HeaderCoerceConfig {
|
||||||
canonicalize bool
|
canonicalize bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// coerce coerces data in the Header by joining keys that match
|
// coerce coerces data in the Header by joining keys that match
|
||||||
// case-insensitively into one entry.
|
// case-insensitively into one entry.
|
||||||
pub fn (mut h Header) coerce(flags ...HeaderCoerceConfig) {
|
pub fn (mut h Header) coerce(flags HeaderCoerceConfig) {
|
||||||
canon := flags.any(it.canonicalize)
|
|
||||||
|
|
||||||
for kl, data_keys in h.keys {
|
for kl, data_keys in h.keys {
|
||||||
master_key := if canon { canonicalize(kl) } else { data_keys[0] }
|
master_key := if flags.canonicalize { canonicalize(kl) } else { data_keys[0] }
|
||||||
|
|
||||||
// save master data
|
// save master data
|
||||||
master_data := h.data[master_key]
|
master_data := h.data[master_key]
|
||||||
|
@ -465,13 +464,14 @@ pub fn (h Header) contains(key CommonHeader) bool {
|
||||||
return h.contains_custom(key.str())
|
return h.contains_custom(key.str())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[params]
|
||||||
pub struct HeaderQueryConfig {
|
pub struct HeaderQueryConfig {
|
||||||
exact bool
|
exact bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// contains_custom returns whether the custom header key exists in the map.
|
// contains_custom returns whether the custom header key exists in the map.
|
||||||
pub fn (h Header) contains_custom(key string, flags ...HeaderQueryConfig) bool {
|
pub fn (h Header) contains_custom(key string, flags HeaderQueryConfig) bool {
|
||||||
if flags.any(it.exact) {
|
if flags.exact {
|
||||||
return key in h.data
|
return key in h.data
|
||||||
}
|
}
|
||||||
return key.to_lower() in h.keys
|
return key.to_lower() in h.keys
|
||||||
|
@ -485,9 +485,9 @@ pub fn (h Header) get(key CommonHeader) ?string {
|
||||||
|
|
||||||
// get_custom gets the first value for the custom header, or none if
|
// get_custom gets the first value for the custom header, or none if
|
||||||
// the key does not exist.
|
// the key does not exist.
|
||||||
pub fn (h Header) get_custom(key string, flags ...HeaderQueryConfig) ?string {
|
pub fn (h Header) get_custom(key string, flags HeaderQueryConfig) ?string {
|
||||||
mut data_key := key
|
mut data_key := key
|
||||||
if !flags.any(it.exact) {
|
if !flags.exact {
|
||||||
// get the first key from key metadata
|
// get the first key from key metadata
|
||||||
k := key.to_lower()
|
k := key.to_lower()
|
||||||
if h.keys[k].len == 0 {
|
if h.keys[k].len == 0 {
|
||||||
|
@ -518,8 +518,8 @@ pub fn (h Header) values(key CommonHeader) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom_values gets all values for the custom header.
|
// custom_values gets all values for the custom header.
|
||||||
pub fn (h Header) custom_values(key string, flags ...HeaderQueryConfig) []string {
|
pub fn (h Header) custom_values(key string, flags HeaderQueryConfig) []string {
|
||||||
if flags.any(it.exact) {
|
if flags.exact {
|
||||||
return h.data[key]
|
return h.data[key]
|
||||||
}
|
}
|
||||||
// case insensitive lookup
|
// case insensitive lookup
|
||||||
|
|
Loading…
Reference in New Issue