Skip to content

Commit

Permalink
Use context for multipart requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
onrik committed Aug 12, 2024
1 parent 26172ed commit 120be91
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (bot *Bot) post(method string, data, target interface{}) error {

// Send POST multipart request to Telegram API
func (bot *Bot) postMultipart(method string, file *fileField, params url.Values, target interface{}) error {
request, err := newMultipartRequest(bot.buildURL(method), file, params)
request, err := newMultipartRequest(bot.ctx, bot.buildURL(method), file, params)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func newPostRequest(ctx context.Context, url string, data interface{}) (*http.Re
return request, nil
}

func newMultipartRequest(url string, file *fileField, params url.Values) (*http.Request, error) {
func newMultipartRequest(ctx context.Context, url string, file *fileField, params url.Values) (*http.Request, error) {
body := new(bytes.Buffer)
writer := multipart.NewWriter(body)

Expand All @@ -91,7 +91,7 @@ func newMultipartRequest(url string, file *fileField, params url.Values) (*http.
return nil, err
}

request, err := http.NewRequest(http.MethodPost, url, body)
request, err := http.NewRequestWithContext(ctx, http.MethodPost, url, body)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 120be91

Please sign in to comment.