File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change 17
17
package config
18
18
19
19
import (
20
+ "encoding/json"
20
21
"fmt"
21
22
"net/http"
22
23
"os"
@@ -50,17 +51,22 @@ var reservedHeaders = map[string]struct{}{
50
51
51
52
// Headers represents the configuration for HTTP headers.
52
53
type Headers struct {
53
- Headers map [string ]Header `yaml:",inline" json:",inline" `
54
+ Headers map [string ]Header `yaml:",inline"`
54
55
dir string
55
56
}
56
57
57
- // Headers represents the configuration for HTTP headers .
58
+ // Header represents the configuration for a single HTTP header .
58
59
type Header struct {
59
60
Values []string `yaml:"values,omitempty" json:"values,omitempty"`
60
61
Secrets []Secret `yaml:"secrets,omitempty" json:"secrets,omitempty"`
61
62
Files []string `yaml:"files,omitempty" json:"files,omitempty"`
62
63
}
63
64
65
+ func (h Headers ) MarshalJSON () ([]byte , error ) {
66
+ // Inline the Headers map when serializing JSON because json encoder doesn't support "inline" directive.
67
+ return json .Marshal (h .Headers )
68
+ }
69
+
64
70
// SetDirectory records the directory to make headers file relative to the
65
71
// configuration file.
66
72
func (h * Headers ) SetDirectory (dir string ) {
Original file line number Diff line number Diff line change @@ -2014,7 +2014,6 @@ func TestHTTPClientConfig_Marshal(t *testing.T) {
2014
2014
ProxyConfig : ProxyConfig {
2015
2015
ProxyURL : URL {proxyURL },
2016
2016
},
2017
- HTTPHeaders : & Headers {},
2018
2017
}
2019
2018
2020
2019
t .Run ("YAML" , func (t * testing.T ) {
@@ -2024,7 +2023,7 @@ func TestHTTPClientConfig_Marshal(t *testing.T) {
2024
2023
proxy_url: "http://localhost:8080"
2025
2024
follow_redirects: false
2026
2025
enable_http2: false
2027
- http_headers: {}
2026
+ http_headers: null
2028
2027
` , string (actualYAML ))
2029
2028
2030
2029
// Unmarshalling the YAML should get the same struct in input.
@@ -2042,7 +2041,7 @@ http_headers: {}
2042
2041
"tls_config":{"insecure_skip_verify":false},
2043
2042
"follow_redirects":false,
2044
2043
"enable_http2":false,
2045
- "http_headers":{}
2044
+ "http_headers":null
2046
2045
}` , string (actualJSON ))
2047
2046
2048
2047
// Unmarshalling the JSON should get the same struct in input.
You can’t perform that action at this time.
0 commit comments