Skip to content

Commit

Permalink
Merge pull request #49 from jfvizoso/master
Browse files Browse the repository at this point in the history
support for headers
  • Loading branch information
unaizorrilla authored Jun 13, 2023
2 parents fee10c4 + 51a1d0e commit 875c19d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.Options;
using Polly;
using System;
using System.Linq;

namespace Microsoft.Extensions.DependencyInjection
{
Expand Down Expand Up @@ -38,6 +39,7 @@ public static IBaleaBuilder AddApiStore(this IBaleaBuilder builder, Action<Store
{
var options = sp.GetRequiredService<IOptions<StoreOptions>>().Value;
client.BaseAddress = options.BaseAddress;
options.Headers?.ToList().ForEach(h => client.DefaultRequestHeaders.Add(h.Key, h.Value));
client.DefaultRequestHeaders.Add(API_KEY_HEADER, options.ApiKey);
})
.AddHttpMessageHandler<LoggingHandler>()
Expand Down
13 changes: 13 additions & 0 deletions src/Balea.Api.Store/Options/StoreOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net.Http.Headers;

namespace Balea.Api.Store.Options
{
Expand All @@ -12,6 +13,7 @@ public class StoreOptions
internal int DurationOfBreak = 30;
internal string ApiKey;
internal Uri BaseAddress;
internal HttpRequestHeaders Headers;

/// <summary>
/// Set the base addres for the Balea Server.
Expand Down Expand Up @@ -83,5 +85,16 @@ public StoreOptions UseDurationOfBreak(int durationOfBreak)
DurationOfBreak = durationOfBreak;
return this;
}

/// <summary>
/// Set the request headers for the client.
/// </summary>
/// <param name="headers">A HttpRequestHeaders object with the desired headers</param>
/// <returns>StoreOptions</returns>
public StoreOptions UseRequestHeaders(HttpRequestHeaders headers)
{
Headers = headers;
return this;
}
}
}

0 comments on commit 875c19d

Please sign in to comment.