Skip to content

Commit dcaeb34

Browse files
Add the possibility to configure default headers of HttpClient (#1738)
1 parent f03c297 commit dcaeb34

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/RestSharp/RestClient.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
using System.Net;
16+
using System.Net.Http.Headers;
1617
using System.Text;
1718
using RestSharp.Authenticators;
1819
using RestSharp.Extensions;
@@ -38,7 +39,7 @@ public partial class RestClient : IDisposable {
3839

3940
internal RestClientOptions Options { get; }
4041

41-
public RestClient(RestClientOptions options) {
42+
public RestClient(RestClientOptions options, Action<HttpRequestHeaders>? configureDefaultHeaders = null) {
4243
UseDefaultSerializers();
4344

4445
Options = options;
@@ -51,8 +52,8 @@ public RestClient(RestClientOptions options) {
5152
var finalHandler = Options.ConfigureMessageHandler?.Invoke(handler) ?? handler;
5253

5354
HttpClient = new HttpClient(finalHandler);
54-
5555
ConfigureHttpClient(HttpClient);
56+
configureDefaultHeaders?.Invoke(HttpClient.DefaultRequestHeaders);
5657
}
5758

5859
/// <summary>
@@ -85,6 +86,7 @@ public RestClient(HttpClient httpClient, RestClientOptions? options = null, bool
8586
Options = options ?? new RestClientOptions();
8687
CookieContainer = new CookieContainer();
8788
_disposeHttpClient = disposeHttpClient;
89+
8890
if (httpClient.BaseAddress != null && Options.BaseUrl == null) {
8991
Options.BaseUrl = httpClient.BaseAddress;
9092
}

0 commit comments

Comments
 (0)