mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-05-08 08:39:20 +00:00
Add X-Kubeshark-Capture: ignore
header to all of the HTTP requests (#1579)
* Add `X-Kubeshark-Capture: ignore` header to all of the HTTP requests * Add `X-Kubeshark-Capture: ignore` header to WebSocket requests * Reduce duplication
This commit is contained in:
parent
377ff44d71
commit
ba126dff51
@ -59,6 +59,7 @@ func runConsole() {
|
||||
Path: "/scripts/logs",
|
||||
}
|
||||
headers := http.Header{}
|
||||
headers.Set(utils.X_KUBESHARK_CAPTURE_HEADER_KEY, utils.X_KUBESHARK_CAPTURE_HEADER_IGNORE_VALUE)
|
||||
headers.Set("License-Key", config.Config.License)
|
||||
|
||||
c, _, err := websocket.DefaultDialer.Dial(u.String(), headers)
|
||||
|
@ -189,6 +189,7 @@ func (connector *Connector) PutScript(script *misc.Script, index int64) (err err
|
||||
log.Error().Err(err).Send()
|
||||
return
|
||||
}
|
||||
utils.AddIgnoreCaptureHeader(req)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("License-Key", config.Config.License)
|
||||
|
||||
@ -228,6 +229,7 @@ func (connector *Connector) DeleteScript(index int64) (err error) {
|
||||
log.Error().Err(err).Send()
|
||||
return
|
||||
}
|
||||
utils.AddIgnoreCaptureHeader(req)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("License-Key", config.Config.License)
|
||||
|
||||
|
@ -8,10 +8,21 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
X_KUBESHARK_CAPTURE_HEADER_KEY = "X-Kubeshark-Capture"
|
||||
X_KUBESHARK_CAPTURE_HEADER_IGNORE_VALUE = "ignore"
|
||||
)
|
||||
|
||||
// Get - When err is nil, resp always contains a non-nil resp.Body.
|
||||
// Caller should close resp.Body when done reading from it.
|
||||
func Get(url string, client *http.Client) (*http.Response, error) {
|
||||
return checkError(client.Get(url))
|
||||
req, err := http.NewRequest(http.MethodPost, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
AddIgnoreCaptureHeader(req)
|
||||
|
||||
return checkError(client.Do(req))
|
||||
}
|
||||
|
||||
// Post - When err is nil, resp always contains a non-nil resp.Body.
|
||||
@ -21,6 +32,7 @@ func Post(url, contentType string, body io.Reader, client *http.Client, licenseK
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
AddIgnoreCaptureHeader(req)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("License-Key", licenseKey)
|
||||
|
||||
@ -51,3 +63,7 @@ func checkError(response *http.Response, errInOperation error) (*http.Response,
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func AddIgnoreCaptureHeader(req *http.Request) {
|
||||
req.Header.Set(X_KUBESHARK_CAPTURE_HEADER_KEY, X_KUBESHARK_CAPTURE_HEADER_IGNORE_VALUE)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user