mirror of
https://github.com/boringproxy/boringproxy.git
synced 2025-02-25 18:55:29 -06:00
Reuse httpClient
This commit is contained in:
@@ -24,10 +24,11 @@ type SmtpConfig struct {
|
||||
}
|
||||
|
||||
type BoringProxy struct {
|
||||
config *BoringProxyConfig
|
||||
db *Database
|
||||
auth *Auth
|
||||
tunMan *TunnelManager
|
||||
config *BoringProxyConfig
|
||||
db *Database
|
||||
auth *Auth
|
||||
tunMan *TunnelManager
|
||||
httpClient *http.Client
|
||||
}
|
||||
|
||||
func Listen() {
|
||||
@@ -65,7 +66,9 @@ func Listen() {
|
||||
|
||||
auth := NewAuth(db)
|
||||
|
||||
p := &BoringProxy{config, db, auth, tunMan}
|
||||
httpClient := &http.Client{}
|
||||
|
||||
p := &BoringProxy{config, db, auth, tunMan, httpClient}
|
||||
|
||||
api := NewApi(config, auth, tunMan)
|
||||
http.Handle("/api/", http.StripPrefix("/api", api))
|
||||
@@ -94,6 +97,8 @@ func Listen() {
|
||||
|
||||
func (p *BoringProxy) proxyRequest(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
log.Println("proxy conn")
|
||||
|
||||
port, err := p.tunMan.GetPort(r.Host)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
@@ -103,8 +108,6 @@ func (p *BoringProxy) proxyRequest(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
httpClient := &http.Client{}
|
||||
|
||||
downstreamReqHeaders := r.Header.Clone()
|
||||
|
||||
upstreamAddr := fmt.Sprintf("localhost:%d", port)
|
||||
@@ -121,7 +124,7 @@ func (p *BoringProxy) proxyRequest(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
upstreamReq.Header = downstreamReqHeaders
|
||||
|
||||
upstreamRes, err := httpClient.Do(upstreamReq)
|
||||
upstreamRes, err := p.httpClient.Do(upstreamReq)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
errMessage := fmt.Sprintf("%s", err)
|
||||
|
||||
Reference in New Issue
Block a user