@@ -112,6 +112,12 @@ func NewHTTPClient(opts *api.ClientOptions) http.Client {
112112 transport = logger .RoundTripper (transport )
113113 }
114114
115+ if opts .Headers == nil {
116+ opts .Headers = map [string ]string {}
117+ }
118+ if ! opts .SkipDefaultHeaders {
119+ resolveHeaders (opts .Headers )
120+ }
115121 transport = newHeaderRoundTripper (opts .Host , opts .AuthToken , opts .Headers , transport )
116122
117123 return http.Client {Transport : transport , Timeout : opts .Timeout }
@@ -148,10 +154,7 @@ type headerRoundTripper struct {
148154 rt http.RoundTripper
149155}
150156
151- func newHeaderRoundTripper (host string , authToken string , headers map [string ]string , rt http.RoundTripper ) http.RoundTripper {
152- if headers == nil {
153- headers = map [string ]string {}
154- }
157+ func resolveHeaders (headers map [string ]string ) {
155158 if _ , ok := headers [contentType ]; ! ok {
156159 headers [contentType ] = jsonContentType
157160 }
@@ -167,11 +170,11 @@ func newHeaderRoundTripper(host string, authToken string, headers map[string]str
167170 }
168171 }
169172 }
170- if _ , ok := headers [authorization ]; ! ok && authToken != "" {
171- headers [authorization ] = fmt .Sprintf ("token %s" , authToken )
172- }
173173 if _ , ok := headers [timeZone ]; ! ok {
174- headers [timeZone ] = currentTimeZone ()
174+ tz := currentTimeZone ()
175+ if tz != "" {
176+ headers [timeZone ] = tz
177+ }
175178 }
176179 if _ , ok := headers [accept ]; ! ok {
177180 // Preview for PullRequest.mergeStateStatus.
@@ -180,6 +183,15 @@ func newHeaderRoundTripper(host string, authToken string, headers map[string]str
180183 a += ", application/vnd.github.nebula-preview"
181184 headers [accept ] = a
182185 }
186+ }
187+
188+ func newHeaderRoundTripper (host string , authToken string , headers map [string ]string , rt http.RoundTripper ) http.RoundTripper {
189+ if _ , ok := headers [authorization ]; ! ok && authToken != "" {
190+ headers [authorization ] = fmt .Sprintf ("token %s" , authToken )
191+ }
192+ if len (headers ) == 0 {
193+ return rt
194+ }
183195 return headerRoundTripper {host : host , headers : headers , rt : rt }
184196}
185197
0 commit comments