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

Permit disabling use of http_proxy #38

Merged
merged 1 commit into from
Feb 6, 2023
Merged
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
29 changes: 25 additions & 4 deletions handle_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"github.com/vbauerster/mpb/v7/decor"
)

var env_prefixes = [...] string {"OSG", "OSDF"}

var p = mpb.New()

// SlowTransferError is an error that is returned when a transfer takes longer than the configured timeout
Expand All @@ -50,6 +52,26 @@ func (e *SlowTransferError) Is(target error) bool {
return ok
}

// Determines whether or not we can interact with the site HTTP proxy
func IsProxyEnabled() bool {
for _, prefix := range env_prefixes {
if _, isSet := os.LookupEnv(prefix + "_DISABLE_HTTP_PROXY"); isSet {
return false
}
}
return true
}

// Determine whether we are allowed to skip the proxy as a fallback
func CanDisableProxy() bool {
for _, prefix := range env_prefixes {
if _, isSet := os.LookupEnv(prefix + "_DISABLE_PROXY_FALLBACK"); isSet {
return false
}
}
return true
}

// ConnectionSetupError is an error that is returned when a connection to the remote server fails
type ConnectionSetupError struct {
URL string
Expand Down Expand Up @@ -97,8 +119,6 @@ func NewTransferDetails(cache Cache, https bool) []TransferDetails {
} else {
cacheEndpoint = cache.Endpoint
}
_, canDisableProxy := os.LookupEnv("OSG_DISABLE_PROXY_FALLBACK")
canDisableProxy = !canDisableProxy

// Form the URL
cacheURL, err := url.Parse(cacheEndpoint)
Expand Down Expand Up @@ -136,11 +156,12 @@ func NewTransferDetails(cache Cache, https bool) []TransferDetails {
if !HasPort(cacheURL.Host) {
cacheURL.Host += ":8000"
}
isProxyEnabled := IsProxyEnabled()
details = append(details, TransferDetails{
Url: *cacheURL,
Proxy: true,
Proxy: isProxyEnabled,
})
if canDisableProxy {
if isProxyEnabled && CanDisableProxy() {
details = append(details, TransferDetails{
Url: *cacheURL,
Proxy: false,
Expand Down