Skip to content

Content-Length header missing for empty POST requests #996

Open
@N1cOs

Description

@N1cOs

Hello! Recently we faced with a problem, that resty Client doesn't set Content-Length header for an empty POST request.

Version - 2.16.5.

Example:

package main

import (
	"fmt"

	"github.com/go-resty/resty/v2"
)

func main() {
	client := resty.New()

	client.OnBeforeRequest(func(client *resty.Client, request *resty.Request) error {
		request.
			SetBody(nil).
			SetContentLength(true)

		return nil
	})

	client = client.SetBaseURL("http://localhost:8080")

	resp, err := client.R().Execute("POST", "/test")
	if err != nil {
		panic(err)
	}

	fmt.Println(resp)
}

Then I captured request with Wireshark and Content-Length header is missing:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions