net/http: if context is canceled, return its error

This permits the error message to distinguish between a context that was
canceled and a context that timed out.

Updates #16381.

Change-Id: I3994b98e32952abcd7ddb5fee08fa1535999be6d
Reviewed-on: https://go-review.googlesource.com/24978
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Ian Lance Taylor 2016-07-15 15:30:53 -07:00
parent 643b9ec07c
commit 0b5f2f0d11
3 changed files with 57 additions and 33 deletions

View file

@ -313,8 +313,8 @@ func TestClientRedirectContext(t *testing.T) {
if !ok {
t.Fatalf("got error %T; want *url.Error", err)
}
if ue.Err != ExportErrRequestCanceled && ue.Err != ExportErrRequestCanceledConn {
t.Errorf("url.Error.Err = %v; want errRequestCanceled or errRequestCanceledConn", ue.Err)
if ue.Err != context.Canceled {
t.Errorf("url.Error.Err = %v; want %v", ue.Err, context.Canceled)
}
}