mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-10-12 01:58:46 +02:00
feat(cli): port the log journal and network journal events to master
This commit is contained in:
1 parent
488065f6e8
commit
37b835c791
109 files changed
+17258
-905
No files matched your search
@@ -5,6 +5,8 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -27,13 +29,25 @@ func newControlClient(addr string) *controlClient {
|
||||
}
|
||||
|
||||
func (c *controlClient) post(path string, data io.Reader) (*http.Response, error) {
|
||||
// for log/send, set the timeout to 5 minutes
|
||||
if path == sendLogsPath {
|
||||
// A log send uploads many megabytes, so it needs more time than the other
|
||||
// calls.
|
||||
if isSendLogsPath(path) {
|
||||
c.c.Timeout = time.Minute * 5
|
||||
}
|
||||
return c.c.Post("http://unix"+path, contentTypeJson, data)
|
||||
}
|
||||
|
||||
// isSendLogsPath reports whether path addresses the log send handler. The path
|
||||
// can carry a query, so the comparison takes the path alone. A path that does
|
||||
// not parse keeps the prefix rule, because it still reaches that handler.
|
||||
func isSendLogsPath(path string) bool {
|
||||
parsed, err := url.Parse(path)
|
||||
if err != nil {
|
||||
return strings.HasPrefix(path, sendLogsPath)
|
||||
}
|
||||
return parsed.Path == sendLogsPath
|
||||
}
|
||||
|
||||
// postStream sends a POST request with no timeout, suitable for long-lived streaming connections.
|
||||
func (c *controlClient) postStream(path string, data io.Reader) (*http.Response, error) {
|
||||
c.c.Timeout = 0
|
||||
|
||||
Reference in new issue
Block a user