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