Skip to content

Commit

Permalink
api: fix TLS when redirecting the request (#1740) (#1777)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx authored and sre-bot committed Oct 9, 2019
1 parent 3ed2d4c commit 6eb8a04
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ tags
/.retools/
vendor
default*
*.bak
.vscode/
19 changes: 18 additions & 1 deletion server/api/redirector.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
package api

import (
"crypto/tls"
"io/ioutil"
"net/http"
"net/url"
"strings"
"sync"

log "github.com/pingcap/log"
"github.com/pingcap/pd/server"
Expand All @@ -33,6 +35,8 @@ const (
errRedirectToNotLeader = "redirect to not leader"
)

var initHTTPClientOnce sync.Once

type redirector struct {
s *server.Server
}
Expand Down Expand Up @@ -67,7 +71,20 @@ func (h *redirector) ServeHTTP(w http.ResponseWriter, r *http.Request, next http
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

initHTTPClientOnce.Do(func() {
var tlsConfig *tls.Config
tlsConfig, err = server.ToTLSConfig(h.s.GetSecurityConfig())
dialClient = &http.Client{
Transport: &http.Transport{
DisableKeepAlives: true,
TLSClientConfig: tlsConfig,
},
}
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
newCustomReverseProxies(urls).ServeHTTP(w, r)
}

Expand Down

0 comments on commit 6eb8a04

Please sign in to comment.