Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pkg/api/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
const (
accept = "Accept"
authorization = "Authorization"
apiVersion = "X-GitHub-Api-Version"
apiVersionValue = "2022-11-28"
contentType = "Content-Type"
github = "github.com"
jsonContentType = "application/json; charset=utf-8"
Expand Down Expand Up @@ -112,7 +114,7 @@ func NewHTTPClient(opts ClientOptions) (*http.Client, error) {
opts.Headers = map[string]string{}
}
if !opts.SkipDefaultHeaders {
resolveHeaders(opts.Headers)
setDefaultHeaders(opts.Headers)
}
transport = newHeaderRoundTripper(opts.Host, opts.AuthToken, opts.Headers, transport)

Expand Down Expand Up @@ -141,7 +143,7 @@ type headerRoundTripper struct {
rt http.RoundTripper
}

func resolveHeaders(headers map[string]string) {
func setDefaultHeaders(headers map[string]string) {
if _, ok := headers[contentType]; !ok {
headers[contentType] = jsonContentType
}
Expand All @@ -163,6 +165,9 @@ func resolveHeaders(headers map[string]string) {
headers[timeZone] = tz
}
}
if _, ok := headers[apiVersion]; !ok {
headers[apiVersion] = apiVersionValue
}
if _, ok := headers[accept]; !ok {
// Preview for PullRequest.mergeStateStatus.
a := "application/vnd.github.merge-info-preview+json"
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func TestNewHTTPClient(t *testing.T) {
wantHeaders: func() http.Header {
h := defaultHeaders()
h.Del(accept)
h.Del(apiVersion)
h.Del(contentType)
h.Del(timeZone)
h.Del(userAgent)
Expand Down Expand Up @@ -169,6 +170,7 @@ func defaultHeaders() http.Header {
h := http.Header{}
a := "application/vnd.github.merge-info-preview+json"
a += ", application/vnd.github.nebula-preview"
h.Set(apiVersion, apiVersionValue)
h.Set(contentType, jsonContentType)
h.Set(userAgent, "go-gh")
h.Set(authorization, fmt.Sprintf("token %s", "oauth_token"))
Expand Down
Loading