Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 8d0ddc0

Browse files
committed
http api support cancel with context
1 parent 2633719 commit 8d0ddc0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

request.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
)
1717

1818
type Request struct {
19+
Ctx context.Context
1920
ApiBase string
2021
Command string
2122
Args []string
@@ -34,6 +35,7 @@ func NewRequest(ctx context.Context, url, command string, args ...string) *Reque
3435
"stream-channels": "true",
3536
}
3637
return &Request{
38+
Ctx: ctx,
3739
ApiBase: url + "/api/v0",
3840
Command: command,
3941
Args: args,
@@ -108,11 +110,13 @@ func (e *Error) Error() string {
108110

109111
func (r *Request) Send(c *http.Client) (*Response, error) {
110112
url := r.getURL()
111-
req, err := http.NewRequest("POST", url, r.Body)
113+
req0, err := http.NewRequest("POST", url, r.Body)
112114
if err != nil {
113115
return nil, err
114116
}
115117

118+
req := req0.WithContext(r.Ctx)
119+
116120
// Add any headers that were supplied via the RequestBuilder.
117121
for k, v := range r.Headers {
118122
req.Header.Add(k, v)

0 commit comments

Comments
 (0)