I wanted to put a situation to you to get your thoughts on the use of Flurl; if I have developed a restful api which is designed to support authentication and sessions from multiple users and you part of the operation of the restful service is that it needs to make authenticated calls to another outside service. If I used the standard flurl implementation of call asyn from a string URL and if I need to set different headers depending on the user that authenticated to my service, would this cause unpredictable behaviour due to it using a single httpclient (as they are all calling the same host).
Asked
Active
Viewed 263 times
1 Answers
1
Doing it the way you describe is completely safe. Setting headers fluently off a URL string or Url
object will apply them to the request, not the client. Example:
await url.WithHeader(name, value).PostAsync(body);
This call can be made a zillion times from different threads with different header values and a single shared HttpClient
instance with no conflicts. This works because under the hood it sets the header on the HttpRequestMessage
, not the default headers on the HttpClient
.

Todd Menier
- 37,557
- 17
- 150
- 173