all: Drop ctxhttp

This package is no longer needed, since we can use the stdlib's
http.NewRequestWithContext.

backend/rclone already did, but it needed a different error check due to
a difference between net/http and ctxhttp.

Also, store the http.Client by value in the REST backend (changed to a
pointer when ctxhttp was introduced) and use errors.WithStack instead
of errors.Wrap where the message was no longer accurate. Errors from
http.NewRequestWithContext will start with "net/http" or "net/url", so
they're easy to identify.
This commit is contained in:
greatroar 2022-10-09 10:21:30 +02:00
parent 1a6160d152
commit d4aadfa389
3 changed files with 27 additions and 32 deletions

View file

@ -22,7 +22,6 @@ import (
"github.com/restic/restic/internal/backend/rest"
"github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/errors"
"golang.org/x/net/context/ctxhttp"
"golang.org/x/net/http2"
)
@ -216,7 +215,7 @@ func newBackend(cfg Config, lim limiter.Limiter) (*Backend, error) {
}()
// send an HTTP request to the base URL, see if the server is there
client := &http.Client{
client := http.Client{
Transport: debug.RoundTripper(tr),
Timeout: cfg.Timeout,
}
@ -231,7 +230,7 @@ func newBackend(cfg Config, lim limiter.Limiter) (*Backend, error) {
}
req.Header.Set("Accept", rest.ContentTypeV2)
res, err := ctxhttp.Do(ctx, client, req)
res, err := client.Do(req)
if err != nil {
// ignore subsequent errors
_ = bg()
@ -240,7 +239,7 @@ func newBackend(cfg Config, lim limiter.Limiter) (*Backend, error) {
// wait for rclone to exit
wg.Wait()
// try to return the program exit code if communication with rclone has failed
if be.waitResult != nil && (err == context.Canceled || errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, syscall.EPIPE)) {
if be.waitResult != nil && (errors.Is(err, context.Canceled) || errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, syscall.EPIPE)) {
err = be.waitResult
}