Skip to content

Commit

Permalink
Expose HttpClient on StreamingHandle (#331)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Quinlivan <rquinlivan@cloudflare.com>
  • Loading branch information
rquinlivan and Robert Quinlivan committed Apr 18, 2023
1 parent 624a4b7 commit 9bd97ef
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions falcon/api_streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import (

// StreamingHandle is higher order type that allows for easy use of CrowdStrike Falcon Streaming API
type StreamingHandle struct {
ctx context.Context
client *client.CrowdStrikeAPISpecification
appId string
offset uint64
stream *models.MainAvailableStreamV2
Events chan *streaming_models.EventItem
Errors chan StreamingError
ctx context.Context
client *client.CrowdStrikeAPISpecification
appId string
offset uint64
stream *models.MainAvailableStreamV2
Events chan *streaming_models.EventItem
Errors chan StreamingError
HTTPClient *http.Client
}

// NewStream initializes new StreamingHandle and connects to the Streaming API.
Expand Down Expand Up @@ -87,8 +88,10 @@ func (sh *StreamingHandle) open() error {
req.Header.Add("Connection", "Keep-Alive")
req.Header.Add("Date", time.Now().Format(time.RFC1123Z))

client := &http.Client{}
resp, err := client.Do(req)
if sh.HTTPClient == nil {
sh.HTTPClient = &http.Client{}
}
resp, err := sh.HTTPClient.Do(req)
if err != nil {
return err
}
Expand Down Expand Up @@ -123,6 +126,7 @@ func (sh *StreamingHandle) open() error {
func (sh *StreamingHandle) Close() {
close(sh.Errors)
sh.Errors = nil
sh.HTTPClient.CloseIdleConnections()
}

func (sh *StreamingHandle) url() string {
Expand Down

0 comments on commit 9bd97ef

Please sign in to comment.