MCPcopy
hub / github.com/crowdsecurity/crowdsec / doQuery

Method doQuery

pkg/longpollclient/client.go:57–81  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

55const timeoutMessage = "no events before timeout"
56
57func (c *LongPollClient) doQuery(ctx context.Context) (*http.Response, error) {
58 logger := c.logger.WithField("method", "doQuery")
59 query := c.url.Query()
60 query.Set("since_time", fmt.Sprintf("%d", c.since))
61 query.Set("timeout", c.timeout)
62 c.url.RawQuery = query.Encode()
63
64 logger.Debugf("Query parameters: %s", c.url.RawQuery)
65
66 req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.url.String(), http.NoBody)
67 if err != nil {
68 logger.Errorf("failed to create request: %s", err)
69 return nil, err
70 }
71 req.Header.Set("Accept", "application/json")
72 resp, err := c.httpClient.Do(req)
73 if err != nil {
74 if errors.Is(err, context.Canceled) {
75 return nil, ctx.Err() // Don't log
76 }
77 logger.Errorf("failed to execute request: %s", err)
78 return nil, err
79 }
80 return resp, nil
81}
82
83func (c *LongPollClient) poll(ctx context.Context) error {
84 logger := c.logger.WithField("method", "poll")

Callers 2

pollMethod · 0.95
PullOnceMethod · 0.95

Calls 5

DoMethod · 0.80
ErrMethod · 0.80
QueryMethod · 0.45
SetMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected