Update bot.go

adding ability to connect bot via proxy with authentification
pull/185/head
min4er 7 years ago committed by GitHub
parent b728fa78fc
commit f735b4c4f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      bot.go

@ -65,8 +65,30 @@ func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (APIResponse,
}
method := fmt.Sprintf(APIEndpoint, bot.Token, endpoint)
// Uncomment for adding ability to connect via proxy
/*proxyStr := "http://proxy.com:3128"
proxyURL, _ := url.Parse(proxyStr)
transport := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
}
bot.Client = &http.Client{
Transport: transport,
}
*/
//==================
resp, err := bot.Client.PostForm(method, params)
// Uncomment for adding auth params to header
/*
auth := "username:password"
basicAuth := "Basic " + base64.StdEncoding.EncodeToString([]byte(auth))
resp.Header.Add("Proxy-Authorization", basicAuth)
*/
//==================
if err != nil {
return APIResponse{}, err
}