Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: go-resty/resty
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.16.1
Choose a base ref
...
head repository: go-resty/resty
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.16.2
Choose a head ref
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Nov 22, 2024

  1. Copy the full SHA
    9a9930f View commit details
  2. release: version bump and readme update for v2.16.2

    jeevatkm committed Nov 22, 2024
    Copy the full SHA
    43d5eca View commit details
  3. Merge pull request #919 from go-resty/fix-buffer-issue

    fix: buffer reuse and back to pool and release v2.16.2
    jeevatkm authored Nov 22, 2024
    Copy the full SHA
    c34e460 View commit details
Showing with 12 additions and 35 deletions.
  1. +3 −3 README.md
  2. +0 −1 client.go
  3. +2 −0 request.go
  4. +2 −4 request_test.go
  5. +1 −1 resty.go
  6. +4 −26 util.go
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,12 +4,12 @@
<p align="center"><a href="#features">Features</a> section describes in detail about Resty capabilities</p>
</p>
<p align="center">
<p align="center"><a href="https://github.com/go-resty/resty/actions/workflows/ci.yml?query=branch%3Av2"><img src="https://github.com/go-resty/resty/actions/workflows/ci.yml/badge.svg?branch=v2" alt="Build Status"></a> <a href="https://app.codecov.io/gh/go-resty/resty/tree/v2"><img src="https://codecov.io/gh/go-resty/resty/branch/v2/graph/badge.svg" alt="Code Coverage"></a> <a href="https://goreportcard.com/report/go-resty/resty"><img src="https://goreportcard.com/badge/go-resty/resty" alt="Go Report Card"></a> <a href="https://github.com/go-resty/resty/releases/latest"><img src="https://img.shields.io/badge/version-2.16.1-blue.svg" alt="Release Version"></a> <a href="https://pkg.go.dev/github.com/go-resty/resty/v2"><img src="https://pkg.go.dev/badge/github.com/go-resty/resty" alt="GoDoc"></a> <a href="LICENSE"><img src="https://img.shields.io/github/license/go-resty/resty.svg" alt="License"></a> <a href="https://github.com/avelino/awesome-go"><img src="https://awesome.re/mentioned-badge.svg" alt="Mentioned in Awesome Go"></a></p>
<p align="center"><a href="https://github.com/go-resty/resty/actions/workflows/ci.yml?query=branch%3Av2"><img src="https://github.com/go-resty/resty/actions/workflows/ci.yml/badge.svg?branch=v2" alt="Build Status"></a> <a href="https://app.codecov.io/gh/go-resty/resty/tree/v2"><img src="https://codecov.io/gh/go-resty/resty/branch/v2/graph/badge.svg" alt="Code Coverage"></a> <a href="https://goreportcard.com/report/go-resty/resty"><img src="https://goreportcard.com/badge/go-resty/resty" alt="Go Report Card"></a> <a href="https://github.com/go-resty/resty/releases/latest"><img src="https://img.shields.io/badge/version-2.16.2-blue.svg" alt="Release Version"></a> <a href="https://pkg.go.dev/github.com/go-resty/resty/v2"><img src="https://pkg.go.dev/badge/github.com/go-resty/resty" alt="GoDoc"></a> <a href="LICENSE"><img src="https://img.shields.io/github/license/go-resty/resty.svg" alt="License"></a> <a href="https://github.com/avelino/awesome-go"><img src="https://awesome.re/mentioned-badge.svg" alt="Mentioned in Awesome Go"></a></p>
</p>

## News

* v2.16.1 [released](https://github.com/go-resty/resty/releases/tag/v2.16.1) and tagged on Nov 19, 2024.
* v2.16.2 [released](https://github.com/go-resty/resty/releases/tag/v2.16.2) and tagged on Nov 21, 2024.
* v2.0.0 [released](https://github.com/go-resty/resty/releases/tag/v2.0.0) and tagged on Jul 16, 2019.
* v1.12.0 [released](https://github.com/go-resty/resty/releases/tag/v1.12.0) and tagged on Feb 27, 2019.
* v1.0 released and tagged on Sep 25, 2017. - Resty's first version was released on Sep 15, 2015 then it grew gradually as a very handy and helpful library. Its been a two years since first release. I'm very thankful to Resty users and its [contributors](https://github.com/go-resty/resty/graphs/contributors).
@@ -105,7 +105,7 @@ Resty author also published following projects for Go Community.

```bash
# Go Modules
require github.com/go-resty/resty/v2 v2.16.1
require github.com/go-resty/resty/v2 v2.16.2
```

## Usage
1 change: 0 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
@@ -1236,7 +1236,6 @@ func (c *Client) executeBefore(req *Request) error {
return wrapNoRetryErr(err)
}

req.RawRequest.Body = newRequestBodyReleaser(req.RawRequest.Body, req.bodyBuf)
return nil
}

2 changes: 2 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
@@ -1030,6 +1030,7 @@ func (r *Request) Execute(method, url string) (*Response, error) {
r.Attempt = 1
resp, err = r.client.execute(r)
r.client.onErrorHooks(r, resp, unwrapNoRetryErr(err))
backToBufPool(r.bodyBuf)
return resp, unwrapNoRetryErr(err)
}

@@ -1059,6 +1060,7 @@ func (r *Request) Execute(method, url string) (*Response, error) {
}

r.client.onErrorHooks(r, resp, unwrapNoRetryErr(err))
backToBufPool(r.bodyBuf)
return resp, unwrapNoRetryErr(err)
}

6 changes: 2 additions & 4 deletions request_test.go
Original file line number Diff line number Diff line change
@@ -2203,10 +2203,8 @@ func TestRequestGH917(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := io.ReadAll(r.Body)
assertError(t, err)
if len(b) > 0 {
// sometimes, the body is "testtest" instead of "test"
assertEqual(t, "test", string(b))
}
assertEqual(t, "test", string(b))

w.WriteHeader(http.StatusInternalServerError)
}))

2 changes: 1 addition & 1 deletion resty.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import (
)

// Version # of resty
const Version = "2.16.1"
const Version = "2.16.2"

// New method creates a new Resty client.
func New() *Client {
30 changes: 4 additions & 26 deletions util.go
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@ import (
"runtime"
"sort"
"strings"
"sync"
)

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
@@ -297,38 +296,17 @@ func acquireBuffer() *bytes.Buffer {

func releaseBuffer(buf *bytes.Buffer) {
if buf != nil {
buf.Reset()
bufPool.Put(buf)
}
}

// requestBodyReleaser wraps requests's body and implements custom Close for it.
// The Close method closes original body and releases request body back to sync.Pool.
type requestBodyReleaser struct {
releaseOnce sync.Once
reqBuf *bytes.Buffer
io.ReadCloser
}

func newRequestBodyReleaser(respBody io.ReadCloser, reqBuf *bytes.Buffer) io.ReadCloser {
if reqBuf == nil {
return respBody
}

return &requestBodyReleaser{
reqBuf: reqBuf,
ReadCloser: respBody,
func backToBufPool(buf *bytes.Buffer) {
if buf != nil {
bufPool.Put(buf)
}
}

func (rr *requestBodyReleaser) Close() error {
err := rr.ReadCloser.Close()
rr.releaseOnce.Do(func() {
releaseBuffer(rr.reqBuf)
})

return err
}

func closeq(v interface{}) {
if c, ok := v.(io.Closer); ok {
silently(c.Close())