Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for HTTP proxy #229

Merged
merged 4 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading