Skip to content
Draft
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
32 changes: 31 additions & 1 deletion HelloDotNet/Hello.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
using System;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using LaunchDarkly.Sdk;
using LaunchDarkly.Sdk.Server;
using LaunchDarkly.Sdk.Server.Integrations;

namespace HelloDotNet
{
/// <summary>
/// A delegating handler that sets the HTTP version to 2.0 on all outgoing requests.
/// This can be used with the LaunchDarkly SDK's HttpConfigurationBuilder.MessageHandler()
/// to force all SDK HTTP traffic to use HTTP/2.
/// </summary>
class Http2Handler : DelegatingHandler
{
public Http2Handler(HttpMessageHandler innerHandler) : base(innerHandler) { }

protected override Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
request.Version = HttpVersion.Version20;
return base.SendAsync(request, cancellationToken);
}
}

class Hello
{
public static void ShowBanner(){
Expand Down Expand Up @@ -36,7 +57,16 @@ static void Main(string[] args)
Environment.Exit(1);
}

var ldConfig = Configuration.Default(SdkKey);
// Configure the SDK to use HTTP/2 by providing a custom message handler
// that sets the HTTP version on every outgoing request.
var handler = new Http2Handler(new SocketsHttpHandler());

var ldConfig = Configuration.Builder(SdkKey)
.Http(
Components.HttpConfiguration()
.MessageHandler(handler)
)
.Build();

var client = new LdClient(ldConfig);

Expand Down