imroc / req

Simple Go HTTP client with Black Magic
https://req.cool
MIT License
4.12k stars 334 forks source link

`SetCommonContentType` is no longer respected when `SetBody()` is called #265

Closed gg718 closed 10 months ago

gg718 commented 10 months ago

Summary

I am not sure exactly when this was broken, but it works as expected in v3.37.2 and does not work in v3.40.1, so at some point between then, calling SetBody on the request seems to disregard the Content-Type set at the global level.

Repro

package main

import (
    "github.com/imroc/req/v3"
)

func main() {
    client := req.C().
        DevMode().
        SetCommonContentType("application/json")

    _, _ = client.R().SetBody("").Post("https://example.com")
}

Expected

...
content-type: application/json; charset=utf-8
...

Actual

...
content-type: text/plain; charset=utf-8
...
imroc commented 10 months ago

Nice catch! It's been fixed in the latest release.

gg718 commented 10 months ago

Thanks for the speedy fix!