I want to pac(proxy automatic configuration) file for proxy environment in net/http package.
But I don’t know how to configure by pac file.
I wish to use like “ProxyFromEnvironment” method in http package.
This package should get you started:
And an example of how to build an http.Transport
that uses it:
"net/url"
"strings"
"github.com/jackwakefield/gopac"
)
var errorProxyRetrieval = errors.New("unable to retrieve proxy")
func newProxyClient(parser *gopac.Parser) *http.Client {
return &http.Client{Transport: &http.Transport{
Proxy: func(req *http.Request) (*url.URL, error) {
// retrieve the proxy entry for the requested URL and host
entry, err := parser.FindProxy(req.URL.String(), req.URL.Host)
if err == nil {
// strip the PROXY prefix, the server delimiter, and then split
// the entry to retrieve an array of proxy servers to be used for
// the request
entry = strings.Replace(entry, "PROXY ", "", -1)
entry = strings.Replace(entry, "; ", "", -1)
hosts := strings.Split(entry, " ")
I wish official support of golang.
I think your suggestion is not given official support.(misunderstanding?)
nathankerr
(nathankerr)
October 3, 2017, 12:35pm
4
There is no “official support” for pac, and it is is extremely unlikely that there will be.
The problem is that a pac file is defined as containing a JavaScript function . That means anything supporting pac requires a complete JavaScript interpreter.
Since pac is not directly supported by the standard library, I responded with the best resources I could find.
I understand.
Thanks for your reply.
system
(system)
Closed
January 3, 2018, 12:02am
6
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.