Last active
August 8, 2022 13:00
-
-
Save MatthewDavidCampbell/d81461900f7631a2ef44af1787d0c7bf to your computer and use it in GitHub Desktop.
Hook when creating request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.OData.Client; | |
using System; | |
using System.Collections.Specialized; | |
using System.Web; | |
namespace Biometria.Discovery.OData | |
{ | |
public static class Extensions | |
{ | |
public static NameValueCollection UseNameValue(this NameValueCollection things, string name, string value) | |
{ | |
things.Set(name, value); | |
return things; | |
} | |
} | |
public class AzureHttpClientRequestMessage : HttpClientRequestMessage | |
{ | |
public override Uri Url { get; set; } | |
protected ConfigurationCache Cache = new ConfigurationCache(); | |
public AzureHttpClientRequestMessage(DataServiceClientRequestMessageArgs args) : base(args) | |
{ | |
Url = new UriBuilder(args.RequestUri) | |
{ | |
Query = HttpUtility | |
.ParseQueryString(args.RequestUri.Query) | |
.UseNameValue("api-version", "2021-04-30-Preview") | |
.ToString() | |
}.Uri; | |
SetHeader("Content-Type", "application/json"); | |
SetHeader("api-key", Cache.GetSearchApiKey().Result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Query string is updated along with the headers but not propagated with the request to Azure Seach