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.4
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.5
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Jan 23, 2025

  1. fix: auth scheme and token from client level #959 (#960)

    jeevatkm authored Jan 23, 2025
    Copy the full SHA
    aee0cb5 View commit details
  2. chore(release): version bump and readme update (#961)

    jeevatkm authored Jan 23, 2025
    Copy the full SHA
    1e19d6b View commit details
Showing with 39 additions and 6 deletions.
  1. +3 −3 README.md
  2. +0 −1 client.go
  3. +2 −0 middleware.go
  4. +33 −1 request_test.go
  5. +1 −1 resty.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.4-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.5-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.4 [released](https://github.com/go-resty/resty/releases/tag/v2.16.4) and tagged on Jan 20, 2025.
* v2.16.5 [released](https://github.com/go-resty/resty/releases/tag/v2.16.5) and tagged on Jan 22, 2025.
* 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.4
require github.com/go-resty/resty/v2 v2.16.5
```

## Usage
1 change: 0 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
@@ -451,7 +451,6 @@ func (c *Client) R() *Request {
RawPathParams: map[string]string{},
Debug: c.Debug,
AuthScheme: c.AuthScheme,
Token: c.Token,

client: c,
multipartFiles: []*File{},
2 changes: 2 additions & 0 deletions middleware.go
Original file line number Diff line number Diff line change
@@ -301,6 +301,8 @@ func addCredentials(c *Client, r *Request) error {
// Build the token Auth header
if !IsStringEmpty(r.Token) {
r.RawRequest.Header.Set(c.HeaderAuthorizationKey, strings.TrimSpace(r.AuthScheme+" "+r.Token))
} else if !IsStringEmpty(c.Token) {
r.RawRequest.Header.Set(c.HeaderAuthorizationKey, strings.TrimSpace(r.AuthScheme+" "+c.Token))
}

return nil
34 changes: 33 additions & 1 deletion request_test.go
Original file line number Diff line number Diff line change
@@ -691,7 +691,7 @@ func TestRequestAuthScheme(t *testing.T) {
assertEqual(t, http.StatusOK, resp.StatusCode())
})

t.Run("empty auth scheme GH954", func(t *testing.T) {
t.Run("empty auth scheme at client level GH954", func(t *testing.T) {
tokenValue := "004DDB79-6801-4587-B976-F093E6AC44FF"

// set client level
@@ -706,6 +706,38 @@ func TestRequestAuthScheme(t *testing.T) {
assertEqual(t, tokenValue, resp.Request.Header.Get(hdrAuthorizationKey))
})

t.Run("empty auth scheme at request level GH954", func(t *testing.T) {
tokenValue := "004DDB79-6801-4587-B976-F093E6AC44FF"

// set client level
c := dc().
SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}).
SetAuthToken(tokenValue)

resp, err := c.R().
SetAuthScheme("").
Get(ts.URL + "/profile")

assertError(t, err)
assertEqual(t, http.StatusOK, resp.StatusCode())
assertEqual(t, tokenValue, resp.Request.Header.Get(hdrAuthorizationKey))
})

t.Run("only client level auth token GH959", func(t *testing.T) {
tokenValue := "004DDB79-6801-4587-B976-F093E6AC44FF"

c := dc().
SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}).
SetAuthToken(tokenValue)

resp, err := c.R().
Get(ts.URL + "/profile")

assertError(t, err)
assertEqual(t, http.StatusOK, resp.StatusCode())
assertEqual(t, "Bearer "+tokenValue, resp.Request.Header.Get(hdrAuthorizationKey))
})

}

func TestRequestDigestAuth(t *testing.T) {
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.4"
const Version = "2.16.5"

// New method creates a new Resty client.
func New() *Client {