Skip to content

Commit

Permalink
Merge pull request #229 from cvarunreddy/main
Browse files Browse the repository at this point in the history
Added support for HTTP proxy
  • Loading branch information
loafoe authored Jul 2, 2024
2 parents 1addc0e + 6d44e30 commit e759712
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ These keys are relevant when using either SigningKey or Service identities
| InsecureSkipVerify | Skip checking HSDP ingestor TLS cert. Insecure! | HSDP\_INSECURE\_SKIP\_VERIFY | Optional |
| SynchronousFlush | Flushes log messages synchronously without batching. By default this is set to *false* | | Optional |
| RetryOnError | Returns retry to FLB if flush fails. Applicable only when *SynchronousFlush* option is set. By default this is set to *false* | | Optional |
| Proxy | HTTP Proxy URL in case there is a proxy redirection required | | Optional |

### Signing keys

Expand Down
13 changes: 12 additions & 1 deletion hsdp/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net/http"
_ "net/http/pprof"
"net/url"
"os"
"runtime/debug"
"strings"
Expand Down Expand Up @@ -84,6 +85,15 @@ func FLBPluginRegister(ctx unsafe.Pointer) int {
return output.FLBPluginRegister(ctx, "hsdp", "HSDP logging output plugin")
}

func GetProxyUrl(proxyUrl string) func(*http.Request) (*url.URL, error) {
if proxyUrl != "" {
return func(req *http.Request) (*url.URL, error) {
return url.Parse(proxyUrl)
}
}
return http.ProxyFromEnvironment
}

//export FLBPluginInit
func FLBPluginInit(ctx unsafe.Pointer) int {
region := plugin.Environment(ctx, "Region")
Expand All @@ -105,6 +115,7 @@ func FLBPluginInit(ctx unsafe.Pointer) int {
dropMessages := plugin.Environment(ctx, "Drop")
synchronous := plugin.Environment(ctx, "SynchronousFlush")
retry := plugin.Environment(ctx, "RetryOnError")
proxyUrl := plugin.Environment(ctx, "Proxy")

var err error

Expand All @@ -130,7 +141,7 @@ func FLBPluginInit(ctx unsafe.Pointer) int {

c := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
Proxy: GetProxyUrl(proxyUrl),
},
}
if ignoreTLS {
Expand Down

0 comments on commit e759712

Please sign in to comment.