Skip to content

Instantly share code, notes, and snippets.

@MatthewDavidCampbell
Last active August 8, 2022 13:00
Show Gist options
  • Save MatthewDavidCampbell/d81461900f7631a2ef44af1787d0c7bf to your computer and use it in GitHub Desktop.
Save MatthewDavidCampbell/d81461900f7631a2ef44af1787d0c7bf to your computer and use it in GitHub Desktop.
Hook when creating request
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);
}
}
}
@MatthewDavidCampbell
Copy link
Author

Query string is updated along with the headers but not propagated with the request to Azure Seach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment