forked from oauth2-proxy/oauth2-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Replace default Go user-agent with oauth2-proxy and version (oa…
…uth2-proxy#2570) * feat: Replace default Go user-agent with oauth2-proxy and version * Add to CHANGELOG * Make userAgentTransport configurable and composable * Use correct naming convention for DefaultHTTPClient * Move version to own package and use named arguments * Update version path in Makefile * Fix import path in Makefile * Change importpath in dist.sh * Minor style issues
- Loading branch information
Showing
11 changed files
with
54 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package requests | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/version" | ||
) | ||
|
||
type userAgentTransport struct { | ||
next http.RoundTripper | ||
userAgent string | ||
} | ||
|
||
func (t *userAgentTransport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
r := req.Clone(req.Context()) | ||
setDefaultUserAgent(r.Header, t.userAgent) | ||
return t.next.RoundTrip(r) | ||
} | ||
|
||
var DefaultHTTPClient = &http.Client{Transport: &userAgentTransport{ | ||
next: http.DefaultTransport, | ||
userAgent: "oauth2-proxy/" + version.VERSION, | ||
}} | ||
|
||
func setDefaultUserAgent(header http.Header, userAgent string) { | ||
if header != nil && len(header.Values("User-Agent")) == 0 { | ||
header.Set("User-Agent", userAgent) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package version | ||
|
||
// VERSION contains version information | ||
var VERSION = "undefined" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters