Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
ad88cf9a
Commit
ad88cf9a
authored
Jul 06, 2015
by
Yu-Ju Hong
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10557 from smarterclayton/override_auth
The bearer token client transport should not override Authorization
parents
1e0a1639
4e7526fc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
0 deletions
+11
-0
transport.go
pkg/client/transport.go
+11
-0
No files found.
pkg/client/transport.go
View file @
ad88cf9a
...
...
@@ -48,11 +48,16 @@ type basicAuthRoundTripper struct {
rt
http
.
RoundTripper
}
// NewBasicAuthRoundTripper will apply a BASIC auth authorization header to a request unless it has
// already been set.
func
NewBasicAuthRoundTripper
(
username
,
password
string
,
rt
http
.
RoundTripper
)
http
.
RoundTripper
{
return
&
basicAuthRoundTripper
{
username
,
password
,
rt
}
}
func
(
rt
*
basicAuthRoundTripper
)
RoundTrip
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
if
len
(
req
.
Header
.
Get
(
"Authorization"
))
!=
0
{
return
rt
.
rt
.
RoundTrip
(
req
)
}
req
=
cloneRequest
(
req
)
req
.
SetBasicAuth
(
rt
.
username
,
rt
.
password
)
return
rt
.
rt
.
RoundTrip
(
req
)
...
...
@@ -63,11 +68,17 @@ type bearerAuthRoundTripper struct {
rt
http
.
RoundTripper
}
// NewBearerAuthRoundTripper adds the provided bearer token to a request unless the authorization
// header has already been set.
func
NewBearerAuthRoundTripper
(
bearer
string
,
rt
http
.
RoundTripper
)
http
.
RoundTripper
{
return
&
bearerAuthRoundTripper
{
bearer
,
rt
}
}
func
(
rt
*
bearerAuthRoundTripper
)
RoundTrip
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
if
len
(
req
.
Header
.
Get
(
"Authorization"
))
!=
0
{
return
rt
.
rt
.
RoundTrip
(
req
)
}
req
=
cloneRequest
(
req
)
req
.
Header
.
Set
(
"Authorization"
,
fmt
.
Sprintf
(
"Bearer %s"
,
rt
.
bearer
))
return
rt
.
rt
.
RoundTrip
(
req
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment