Skip to content

Commit

Permalink
Merge pull request #1 from xurwxj/xdev
Browse files Browse the repository at this point in the history
add custom proxy to Remote
  • Loading branch information
xurwxj authored May 13, 2021
2 parents 5791b61 + 7a21fef commit 3239e7e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions net/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
stdUrl "net/url"
"strings"
"time"

validator "github.com/go-playground/validator/v10"
"github.com/xurwxj/gtils/validators"
"github.com/xurwxj/viper"
"gopkg.in/h2non/gentleman.v2"
"gopkg.in/h2non/gentleman.v2/plugins/body"
)
Expand Down Expand Up @@ -54,9 +57,21 @@ func Remote(url, method string, body io.Reader, header map[string]string) ([]byt
var req *http.Request
var res *http.Response
var err error

proxyHandler := http.ProxyFromEnvironment
if proxyUrl := viper.GetString("HTTP_PROXY"); proxyUrl != "" {
proxyUri, err := stdUrl.Parse(proxyUrl)
if err != nil {
log.Println(err)
} else {
proxyHandler = http.ProxyURL(proxyUri)
}
}

client := &http.Client{Transport: &http.Transport{
Dial: PrintLocalDial,
DisableKeepAlives: true,
Proxy: proxyHandler,
}}
req, err = http.NewRequest(method, url, body)

Expand Down

0 comments on commit 3239e7e

Please sign in to comment.