Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 RestClient(RestClientOptions options) {
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 RestClient(HttpClient httpClient, RestClientOptions? options = null, bool
Options = options ?? new RestClientOptions();
CookieContainer = new CookieContainer();
_disposeHttpClient = disposeHttpClient;

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