From 7f99cc72ef2c5e672f280cf047d4671c506f7d94 Mon Sep 17 00:00:00 2001 From: Dean Karn Date: Tue, 9 May 2023 12:29:27 -0700 Subject: [PATCH] fix closing of body prematurely --- CHANGELOG.md | 7 ++++++- README.md | 2 +- net/http/retryable.go | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b95bf7..3202122 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [5.17.2] - 2023-05-09 +### Fixed +- Prematurely closing http.Response Body before error with it can be intercepted for ErrUnexpectedResponse. + ## [5.17.1] - 2023-05-09 ### Fixed - ErrRetryableStatusCode passing the *http.Response to have access to not only the status code but headers etc. related to retrying. @@ -42,7 +46,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added `timext.NanoTime` for fast low level monotonic time with nanosecond precision. -[Unreleased]: https://github.com/go-playground/pkg/compare/v5.17.1...HEAD +[Unreleased]: https://github.com/go-playground/pkg/compare/v5.17.2...HEAD +[5.17.2]: https://github.com/go-playground/pkg/compare/v5.17.1..v5.17.2 [5.17.1]: https://github.com/go-playground/pkg/compare/v5.17.0...v5.17.1 [5.17.0]: https://github.com/go-playground/pkg/compare/v5.16.0...v5.17.0 [5.16.0]: https://github.com/go-playground/pkg/compare/v5.15.2...v5.16.0 diff --git a/README.md b/README.md index ac0519b..c403ba5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # pkg -![Project status](https://img.shields.io/badge/version-5.17.1-green.svg) +![Project status](https://img.shields.io/badge/version-5.17.2-green.svg) [![Lint & Test](https://github.com/go-playground/pkg/actions/workflows/go.yml/badge.svg)](https://github.com/go-playground/pkg/actions/workflows/go.yml) [![Coverage Status](https://coveralls.io/repos/github/go-playground/pkg/badge.svg?branch=master)](https://coveralls.io/github/go-playground/pkg?branch=master) [![GoDoc](https://godoc.org/github.com/go-playground/pkg?status.svg)](https://pkg.go.dev/mod/github.com/go-playground/pkg/v5) diff --git a/net/http/retryable.go b/net/http/retryable.go index 7d897fc..b653424 100644 --- a/net/http/retryable.go +++ b/net/http/retryable.go @@ -110,11 +110,11 @@ func DoRetryable[T any](ctx context.Context, isRetryableFn errorsext.IsRetryable return resultext.Err[T, error](result.Err()) } resp := result.Unwrap() - defer resp.Body.Close() if resp.StatusCode != expectedResponseCode { return resultext.Err[T, error](ErrUnexpectedResponse{Response: resp}) } + defer resp.Body.Close() data, err := DecodeResponse[T](resp, maxMemory) if err != nil {