Repository: go-resty/resty (go)

Issue:
How to set Content-Lenght=0 with nil Body?
resty v2.7.0
go 1.20

I use the following code to test:

```go
func main() {
	c := resty.New()

	c.SetPreRequestHook(func(c *resty.Client, r *http.Request) error {
		fmt.Println("zzzzzz", r.Body)
		return nil
	})

	c.R().SetContentLength(true).SetBody(nil).Get("http://10.233.32.117:12233")
}
```

I got following on stdout:

```
zzzzz {}
```

It seems that the rawBody is reassigned to `{}`

And I got following on tcpdump:

```
GET / HTTP/1.1
Host: 10.233.32.117:12233
User-Agent: go-resty/2.7.0 (https://github.com/go-resty/resty)
Accept-Encoding: gzip

.....
```

It seems that although I set the `nil` body and `setContentLength=true`，its not working as expected? anything I missed?

Pull request description:
Set ContentLength to 0 when Body is nil
To address the issue https://github.com/go-resty/resty/issues/671 set `ContentLength` header to 0 when Body is `nil` and `setContentLength` was set to `true`.

Closes #671 

Patch:
diff --git a/middleware.go b/middleware.go
index 9b19c46..2b33b13 100644
--- a/middleware.go
+++ b/middleware.go
@@ -166,8 +166,12 @@ func parseRequestBody(c *Client, r *Request) (err error) {
 
 CL:
 	// by default resty won't set content length, you can if you want to :)
-	if (c.setContentLength || r.setContentLength) && r.bodyBuf != nil {
-		r.Header.Set(hdrContentLengthKey, fmt.Sprintf("%d", r.bodyBuf.Len()))
+	if c.setContentLength || r.setContentLength {
+		if r.bodyBuf == nil {
+			r.Header.Set(hdrContentLengthKey, "0")
+		} else {
+			r.Header.Set(hdrContentLengthKey, fmt.Sprintf("%d", r.bodyBuf.Len()))
+		}
 	}
 
 	return


Test patch:
diff --git a/client_test.go b/client_test.go
index da098fb..4a27ecf 100644
--- a/client_test.go
+++ b/client_test.go
@@ -488,6 +488,17 @@ func TestClientOptions(t *testing.T) {
 	assertEqual(t, client.closeConnection, true)
 }
 
+func TestContentLengthWhenBodyIsNil(t *testing.T) {
+	client := dc()
+
+	client.SetPreRequestHook(func(c *Client, r *http.Request) error {
+		assertEqual(t, "0", r.Header.Get(hdrContentLengthKey))
+		return nil
+	})
+
+	client.R().SetContentLength(true).SetBody(nil).Get("http://localhost")
+}
+
 func TestClientPreRequestHook(t *testing.T) {
 	client := dc()
 	client.SetPreRequestHook(func(c *Client, r *http.Request) error {