context timeout for postmsg

This commit is contained in:
Ted Unangst 2020-05-09 19:25:25 -04:00
parent b7f732ce82
commit c2454d117d
1 changed files with 4 additions and 0 deletions

View File

@ -17,6 +17,7 @@ package main
import ( import (
"bytes" "bytes"
"context"
"database/sql" "database/sql"
"errors" "errors"
"fmt" "fmt"
@ -69,6 +70,9 @@ func PostMsg(keyname string, key httpsig.PrivateKey, url string, msg []byte) err
req.Header.Set("User-Agent", "honksnonk/5.0; "+serverName) req.Header.Set("User-Agent", "honksnonk/5.0; "+serverName)
req.Header.Set("Content-Type", theonetruename) req.Header.Set("Content-Type", theonetruename)
httpsig.SignRequest(keyname, key, req, msg) httpsig.SignRequest(keyname, key, req, msg)
ctx, cancel := context.WithTimeout(context.Background(), 1 * time.Minute)
defer cancel()
req = req.WithContext(ctx)
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
return err return err