Skip to content

Commit

Permalink
Add new httpClient parameter to NewCollector (can be nil)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Sep 11, 2024
1 parent 19f4aaa commit 7f8c3f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions logging/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ type Collector struct {
}

// NewCollector initializes and returns a new Collector
func NewCollector(maxSize int, endpoint, login, password string) *Collector {
func NewCollector(maxSize int, endpoint, login, password string, httpClient *http.Client) *Collector {
auth := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", login, password)))
if httpClient == nil {
httpClient = &http.Client{}
}
return &Collector{
records: make([]HTTPRecord, 0, maxSize),
maxSize: maxSize,
endpoint: endpoint,
httpClient: &http.Client{},
httpClient: httpClient,
authHeader: "Basic " + auth,
}
}
Expand Down
2 changes: 1 addition & 1 deletion logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func LogRequest(w http.ResponseWriter, r *http.Request, start time.Time, cauth s
if maxSize == 0 {
maxSize = 1000
}
LogCollector = NewCollector(maxSize, CollectorURL, CollectorLogin, CollectorPassword)
LogCollector = NewCollector(maxSize, CollectorURL, CollectorLogin, CollectorPassword, nil)
}

// our apache configuration
Expand Down

0 comments on commit 7f8c3f6

Please sign in to comment.