0

I recently upgraded RestSharp to 107.3.0 in the hope to fix some connectivity issues (as mentioned in the documentation).

After 1 hour of being live on production with this upgrade, my targetted API started throwing '400 Bad Request - Headers too long'. A recycle was only a temporary fix.

When I use Fiddler to see my API calls (locally), I noticed that the User-agent header contains:

RestSharp/107.3.0.0 RestSharp/107.3.0.0 RestSharp/107.3.0.0 (...)

... and each next call adds the agent name to the growing header value until the header is, well, just too long.

Anyone else experienced this before?

Frederik V
  • 163
  • 1
  • 8

1 Answers1

1

Turns out I was creating a RestClient(httpClient) object each time, but re-using the same HTTP client. Creating an instance of RestClient initializes some default headers, resulting in infinitely adding the user agent header value.

Re-using the RestClient as well, fixed the behavior.

Frederik V
  • 163
  • 1
  • 8
  • 1
    There's a PR that adds a constructor for accepting an `HttpClient` issue and not changing anything there (no header, no timeout). It hasn't been merged yet. I will also try to fix this issue, it should be replacing the header, not adding it. But your solution is correct anyway. – Alexey Zimarev Mar 13 '22 at 11:43