Skip to content

Commit 3d33532

Browse files
ianlancetaylorgopherbot
authored andcommitted
net/http: let ErrNotSupported match errors.ErrUnsupported
For #41198 Change-Id: Ibb030e94618a1f594cfd98ddea214ad7a88d2e73 Reviewed-on: https://go-review.googlesource.com/c/go/+/494122 Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Damien Neil <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 945a2b1 commit 3d33532

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

api/next/41198.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pkg errors, var ErrUnsupported error #41198
2+
pkg net/http, method (*ProtocolError) Is(error) bool #41198

src/net/http/request.go

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ type ProtocolError struct {
4848

4949
func (pe *ProtocolError) Error() string { return pe.ErrorString }
5050

51+
// Is lets http.ErrNotSupported match errors.ErrUnsupported.
52+
func (pe *ProtocolError) Is(err error) bool {
53+
return pe == ErrNotSupported && err == errors.ErrUnsupported
54+
}
55+
5156
var (
5257
// ErrNotSupported indicates that a feature is not supported.
5358
//

src/net/http/request_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"context"
1111
"crypto/rand"
1212
"encoding/base64"
13+
"errors"
1314
"fmt"
1415
"io"
1516
"math"
@@ -1388,3 +1389,9 @@ func runFileAndServerBenchmarks(b *testing.B, mode testMode, f *os.File, n int64
13881389
b.SetBytes(n)
13891390
}
13901391
}
1392+
1393+
func TestErrNotSupported(t *testing.T) {
1394+
if !errors.Is(ErrNotSupported, errors.ErrUnsupported) {
1395+
t.Error("errors.Is(ErrNotSupported, errors.ErrUnsupported) failed")
1396+
}
1397+
}

0 commit comments

Comments
 (0)