Skip to content

Commit

Permalink
close tikv#4490: fix exported var problem
Browse files Browse the repository at this point in the history
Signed-off-by: Cabinfever_B <[email protected]>
  • Loading branch information
CabinfeverB committed Dec 28, 2021
1 parent b78a7b3 commit 6998af2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
31 changes: 28 additions & 3 deletions pkg/apiutil/apiutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
)

var (
<<<<<<< HEAD
<<<<<<< HEAD
// componentSignatureKey is used for http request header key
// to identify component signature
Expand All @@ -41,6 +42,13 @@ var (
// ComponentAnonymousValue identifies anonymous request source
ComponentAnonymousValue = "anonymous"
>>>>>>> baa5163b (close #4490: add teset)
=======
// componentSignatureKey is used for http request header key
// to identify component signature
componentSignatureKey = "component"
// componentAnonymousValue identifies anonymous request source
componentAnonymousValue = "anonymous"
>>>>>>> e904c838 (close #4490: fix exported var problem)
)

// DeferClose captures the error returned from closing (if an error occurs).
Expand Down Expand Up @@ -156,10 +164,14 @@ func GetComponentNameOnHTTP(r *http.Request) string {

// GetComponentNameOnHTTP returns component name from Request Header
func GetComponentNameOnHTTP(r *http.Request) string {
componentName := r.Header.Get(ComponentSignatureKey)
componentName := r.Header.Get(componentSignatureKey)
if componentName == "" {
<<<<<<< HEAD
componentName = ComponentAnonymousValue
>>>>>>> baa5163b (close #4490: add teset)
=======
componentName = componentAnonymousValue
>>>>>>> e904c838 (close #4490: fix exported var problem)
}
return componentName
}
Expand Down Expand Up @@ -205,16 +217,29 @@ type UserSignatureRoundTripper struct {
=======
// ComponentSignatureRoundTripper is used to add component signature in HTTP header
type ComponentSignatureRoundTripper struct {
<<<<<<< HEAD
>>>>>>> d4c21796 (close #4490: add comment)
Proxied http.RoundTripper
Component string
=======
proxied http.RoundTripper
component *string
}

// NewComponentSignatureRoundTripper returns a new ComponentSignatureRoundTripper.
func NewComponentSignatureRoundTripper(roundTripper http.RoundTripper, componentName *string) *ComponentSignatureRoundTripper {
return &ComponentSignatureRoundTripper{
proxied: roundTripper,
component: componentName,
}
>>>>>>> e904c838 (close #4490: fix exported var problem)
}

// RoundTrip is used to implement RoundTripper
func (rt *ComponentSignatureRoundTripper) RoundTrip(req *http.Request) (resp *http.Response, err error) {
req.Header.Add(ComponentSignatureKey, rt.Component)
req.Header.Add(componentSignatureKey, *rt.component)
// Send the request, get the response and the error
resp, err = rt.Proxied.RoundTrip(req)
resp, err = rt.proxied.RoundTrip(req)
return
}
>>>>>>> baa5163b (close #4490: add teset)
11 changes: 11 additions & 0 deletions tools/pd-ctl/pdctl/command/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
)

var (
<<<<<<< HEAD
<<<<<<< HEAD
pdControllerComponentName = "pdctl"
dialClient = &http.Client{
Expand All @@ -48,6 +49,11 @@ var (
Proxied: http.DefaultTransport,
},
>>>>>>> 377c854c (close #4490: fix transport and change component key)
=======
pdControllerComponentName = "pdctl"
dialClient = &http.Client{
Transport: apiutil.NewComponentSignatureRoundTripper(http.DefaultTransport, &pdControllerComponentName),
>>>>>>> e904c838 (close #4490: fix exported var problem)
}
pingPrefix = "pd/api/v1/ping"
)
Expand All @@ -66,6 +72,7 @@ func InitHTTPSClient(caPath, certPath, keyPath string) error {

dialClient = &http.Client{
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
Transport: apiutil.NewComponentSignatureRoundTripper(
&http.Transport{TLSClientConfig: tlsConfig}, &pdControllerComponentName),
Expand All @@ -79,6 +86,10 @@ func InitHTTPSClient(caPath, certPath, keyPath string) error {
TLSClientConfig: tlsConfig},
},
>>>>>>> baa5163b (close #4490: add teset)
=======
Transport: apiutil.NewComponentSignatureRoundTripper(
&http.Transport{TLSClientConfig: tlsConfig}, &pdControllerComponentName),
>>>>>>> e904c838 (close #4490: fix exported var problem)
}

return nil
Expand Down

0 comments on commit 6998af2

Please sign in to comment.