Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Make Authorization-Token Configurable #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 19 additions & 3 deletions WebApiThrottle/ThrottlingHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -129,6 +129,22 @@ public ThrottlePolicy Policy
/// </summary>
public HttpStatusCode QuotaExceededResponseCode { get; set; }

private string tokenKey = "Authorization-Token";

public string AuthorizationToken
{
get { return tokenKey; }
set
{
if (string.IsNullOrEmpty(tokenKey))
{
throw new ArgumentNullException(nameof(AuthorizationToken));
}

tokenKey = value;
}
}

protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
// get policy from repo
Expand Down Expand Up @@ -227,8 +243,8 @@ protected virtual RequestIdentity SetIdentity(HttpRequestMessage request)
var entry = new RequestIdentity();
entry.ClientIp = core.GetClientIp(request).ToString();
entry.Endpoint = request.RequestUri.AbsolutePath.ToLowerInvariant();
entry.ClientKey = request.Headers.Contains("Authorization-Token")
? request.Headers.GetValues("Authorization-Token").First()
entry.ClientKey = request.Headers.Contains(AuthorizationToken)
? request.Headers.GetValues(AuthorizationToken).First()
: "anon";

return entry;
Expand Down