Skip to content

Commit

Permalink
Add the possibility to configure default headers of HttpClient (#1738)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed Feb 7, 2022
1 parent f03c297 commit dcaeb34
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/RestSharp/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

using System.Net;
using System.Net.Http.Headers;
using System.Text;
using RestSharp.Authenticators;
using RestSharp.Extensions;
Expand All @@ -38,7 +39,7 @@ public partial class RestClient : IDisposable {

internal RestClientOptions Options { get; }

public RestClient(RestClientOptions options) {
public RestClient(RestClientOptions options, Action<HttpRequestHeaders>? configureDefaultHeaders = null) {
UseDefaultSerializers();

Options = options;
Expand All @@ -51,8 +52,8 @@ public partial class RestClient : IDisposable {
var finalHandler = Options.ConfigureMessageHandler?.Invoke(handler) ?? handler;

HttpClient = new HttpClient(finalHandler);

ConfigureHttpClient(HttpClient);
configureDefaultHeaders?.Invoke(HttpClient.DefaultRequestHeaders);
}

/// <summary>
Expand Down Expand Up @@ -85,6 +86,7 @@ public partial class RestClient : IDisposable {
Options = options ?? new RestClientOptions();
CookieContainer = new CookieContainer();
_disposeHttpClient = disposeHttpClient;

if (httpClient.BaseAddress != null && Options.BaseUrl == null) {
Options.BaseUrl = httpClient.BaseAddress;
}
Expand Down

0 comments on commit dcaeb34

Please sign in to comment.