@@ -7,25 +7,28 @@ import (
77 "errors"
88 "fmt"
99 "io"
10+ "net/http"
1011 "os"
12+ "strings"
1113 "time"
1214)
1315
1416const (
15- DefaultLogLevelString = "LogLevelInfo"
16- DefaultLogOutputFormatString = "pretty"
17- DefaultLogConsoleSeparator = " "
18- DefaultLogExportPath = "/defaultlogs"
19- DefaultMaxRetryAttempts = 3
20- DefaultMaxConcurrentRequests = 1
21- DefaultExportLogs = false
22- DefaultHideSensitiveData = false
23- DefaultEnableDynamicRateLimiting = false
24- DefaultCustomTimeout = 5 * time .Second
25- DefaultTokenRefreshBufferPeriod = 2 * time .Minute
26- DefaultTotalRetryDuration = 5 * time .Minute
27- DefaultFollowRedirects = false
28- DefaultMaxRedirects = 5
17+ DefaultLogLevelString = "LogLevelInfo"
18+ DefaultLogOutputFormatString = "pretty"
19+ DefaultLogConsoleSeparator = " "
20+ DefaultLogExportPath = "/defaultlogs"
21+ DefaultMaxRetryAttempts = 3
22+ DefaultMaxConcurrentRequests = 1
23+ DefaultExportLogs = false
24+ DefaultHideSensitiveData = false
25+ DefaultEnableDynamicRateLimiting = false
26+ DefaultCustomTimeout = 5 * time .Second
27+ DefaultTokenRefreshBufferPeriod = 2 * time .Minute
28+ DefaultTotalRetryDuration = 5 * time .Minute
29+ DefaultFollowRedirects = false
30+ DefaultMaxRedirects = 5
31+ DefaultEnableConcurrencyManagement = false
2932)
3033
3134// LoadConfigFromFile loads http client configuration settings from a JSON file.
@@ -62,15 +65,32 @@ func LoadConfigFromFile(filepath string) (*ClientConfig, error) {
6265// If any environment variables are not set, the default values defined in the constants are used instead.
6366func LoadConfigFromEnv () (* ClientConfig , error ) {
6467 config := & ClientConfig {
65- HideSensitiveData : getEnvAsBool ("HIDE_SENSITIVE_DATA" , DefaultHideSensitiveData ),
66- MaxRetryAttempts : getEnvAsInt ("MAX_RETRY_ATTEMPTS" , DefaultMaxRetryAttempts ),
67- MaxConcurrentRequests : getEnvAsInt ("MAX_CONCURRENT_REQUESTS" , DefaultMaxConcurrentRequests ),
68- EnableDynamicRateLimiting : getEnvAsBool ("ENABLE_DYNAMIC_RATE_LIMITING" , DefaultEnableDynamicRateLimiting ),
69- CustomTimeout : getEnvAsDuration ("CUSTOM_TIMEOUT" , DefaultCustomTimeout ),
70- TokenRefreshBufferPeriod : getEnvAsDuration ("TOKEN_REFRESH_BUFFER_PERIOD" , DefaultTokenRefreshBufferPeriod ),
71- TotalRetryDuration : getEnvAsDuration ("TOTAL_RETRY_DURATION" , DefaultTotalRetryDuration ),
72- FollowRedirects : getEnvAsBool ("FOLLOW_REDIRECTS" , DefaultFollowRedirects ),
73- MaxRedirects : getEnvAsInt ("MAX_REDIRECTS" , DefaultMaxRedirects ),
68+ HideSensitiveData : getEnvAsBool ("HIDE_SENSITIVE_DATA" , DefaultHideSensitiveData ),
69+ MaxRetryAttempts : getEnvAsInt ("MAX_RETRY_ATTEMPTS" , DefaultMaxRetryAttempts ),
70+ MaxConcurrentRequests : getEnvAsInt ("MAX_CONCURRENT_REQUESTS" , DefaultMaxConcurrentRequests ),
71+ EnableDynamicRateLimiting : getEnvAsBool ("ENABLE_DYNAMIC_RATE_LIMITING" , DefaultEnableDynamicRateLimiting ),
72+ CustomTimeout : getEnvAsDuration ("CUSTOM_TIMEOUT" , DefaultCustomTimeout ),
73+ TokenRefreshBufferPeriod : getEnvAsDuration ("TOKEN_REFRESH_BUFFER_PERIOD" , DefaultTokenRefreshBufferPeriod ),
74+ TotalRetryDuration : getEnvAsDuration ("TOTAL_RETRY_DURATION" , DefaultTotalRetryDuration ),
75+ FollowRedirects : getEnvAsBool ("FOLLOW_REDIRECTS" , DefaultFollowRedirects ),
76+ MaxRedirects : getEnvAsInt ("MAX_REDIRECTS" , DefaultMaxRedirects ),
77+ EnableConcurrencyManagement : getEnvAsBool ("ENABLE_CONCURRENCY_MANAGEMENT" , DefaultEnableConcurrencyManagement ),
78+ }
79+
80+ // Load custom cookies from environment variables.
81+ customCookies := getEnvAsString ("CUSTOM_COOKIES" , "" )
82+ if customCookies != "" {
83+ cookies := []* http.Cookie {}
84+ for _ , cookie := range strings .Split (customCookies , ";" ) {
85+ parts := strings .SplitN (cookie , "=" , 2 )
86+ if len (parts ) == 2 {
87+ cookies = append (cookies , & http.Cookie {
88+ Name : parts [0 ],
89+ Value : parts [1 ],
90+ })
91+ }
92+ }
93+ config .CustomCookies = cookies
7494 }
7595
7696 return config , nil
0 commit comments