Skip to content

Commit

Permalink
net/http: let ErrNotSupported match errors.ErrUnsupported
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ianlancetaylor authored and gopherbot committed May 10, 2023
1 parent 945a2b1 commit 3d33532
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/next/41198.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pkg errors, var ErrUnsupported error #41198
pkg net/http, method (*ProtocolError) Is(error) bool #41198
5 changes: 5 additions & 0 deletions src/net/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ type ProtocolError struct {

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

// Is lets http.ErrNotSupported match errors.ErrUnsupported.
func (pe *ProtocolError) Is(err error) bool {
return pe == ErrNotSupported && err == errors.ErrUnsupported
}

var (
// ErrNotSupported indicates that a feature is not supported.
//
Expand Down
7 changes: 7 additions & 0 deletions src/net/http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"context"
"crypto/rand"
"encoding/base64"
"errors"
"fmt"
"io"
"math"
Expand Down Expand Up @@ -1388,3 +1389,9 @@ func runFileAndServerBenchmarks(b *testing.B, mode testMode, f *os.File, n int64
b.SetBytes(n)
}
}

func TestErrNotSupported(t *testing.T) {
if !errors.Is(ErrNotSupported, errors.ErrUnsupported) {
t.Error("errors.Is(ErrNotSupported, errors.ErrUnsupported) failed")
}
}

0 comments on commit 3d33532

Please sign in to comment.