Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetMultipartFormData not work for retry #974

Open
kklll opened this issue Feb 20, 2025 · 0 comments
Open

SetMultipartFormData not work for retry #974

kklll opened this issue Feb 20, 2025 · 0 comments

Comments

@kklll
Copy link

kklll commented Feb 20, 2025

go version go1.23.1 darwin/arm64
resty version go-resty/2.16.5

Hello developer, I used the SetMultipartFormData() method while using AddRetryCondition(retryCondition), and found that if the first request fails and enters the retry phase, SetMultipartFormData() is inconsistent with the source request during the retry phase.
I don't know if there is a problem with the way I use it or if it is a bug in the software itself. I look forward to your feedback. The following is the reproduction code。

func retryCondition(r *resty.Response, e error) bool {
	if e != nil {
		return true
	}
	if r != nil && r.StatusCode() >= http.StatusBadRequest {
		return true
	}
	return false
}
func test() {
	var resp *resty.Response
	client := resty.New().
		EnableTrace().
		SetTimeout(time.Second * 30).
		SetRetryCount(1).
		SetRetryWaitTime(time.Millisecond * 10).
		AddRetryCondition(retryCondition).
		SetDebug(true)
	resp, err := client.R().SetMultipartFormData(
		map[string]string{
			"url": "https://www.google.com/",
		}).Post("https://httpbin.org/status/403")
	if err != nil {
		fmt.Println(err)
	}
	if resp.IsError() {
		fmt.Println(resp.String())
	}
	fmt.Println(resp.StatusCode())
}

this is debug log :

2025/02/20 19:21:03.795499 DEBUG RESTY 
==============================================================================
~~~ REQUEST ~~~
POST  /status/403  HTTP/1.1
HOST   : httpbin.org
HEADERS:
	Content-Type: multipart/form-data; boundary=738e8d15e8c2178650747f740ba92157061894c1441125421a35abb61923
	User-Agent: go-resty/2.16.5 (https://github.com/go-resty/resty)
BODY   :
--738e8d15e8c2178650747f740ba92157061894c1441125421a35abb61923
Content-Disposition: form-data; name="url"

https://www.google.com/
--738e8d15e8c2178650747f740ba92157061894c1441125421a35abb61923--

------------------------------------------------------------------------------
~~~ RESPONSE ~~~
STATUS       : 403 Forbidden
PROTO        : HTTP/2.0
RECEIVED AT  : 2025-02-20T19:21:03.794705+08:00
TIME DURATION: 982.11075ms
HEADERS      :
	Access-Control-Allow-Credentials: true
	Access-Control-Allow-Origin: *
	Content-Length: 0
	Content-Type: text/html; charset=utf-8
	Date: Thu, 20 Feb 2025 11:21:03 GMT
	Server: gunicorn/19.9.0
BODY         :
***** NO CONTENT *****
==============================================================================
2025/02/20 19:21:04.032893 DEBUG RESTY 
==============================================================================
~~~ REQUEST ~~~
POST  /status/403  HTTP/1.1
HOST   : httpbin.org
HEADERS:
	Content-Type: multipart/form-data; boundary=f8c0e40e8c61861241d9bc3e210f8e535d1db1dba6e8537b43dd1aafeada
	User-Agent: go-resty/2.16.5 (https://github.com/go-resty/resty)
BODY   :
--f8c0e40e8c61861241d9bc3e210f8e535d1db1dba6e8537b43dd1aafeada
Content-Disposition: form-data; name="url"


--f8c0e40e8c61861241d9bc3e210f8e535d1db1dba6e8537b43dd1aafeada--

------------------------------------------------------------------------------
~~~ RESPONSE ~~~
STATUS       : 403 Forbidden
PROTO        : HTTP/2.0
RECEIVED AT  : 2025-02-20T19:21:04.03283+08:00
TIME DURATION: 224.686208ms
HEADERS      :
	Access-Control-Allow-Credentials: true
	Access-Control-Allow-Origin: *
	Content-Length: 0
	Content-Type: text/html; charset=utf-8
	Date: Thu, 20 Feb 2025 11:21:03 GMT
	Server: gunicorn/19.9.0
BODY         :
***** NO CONTENT *****
==============================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant