|
1 | 1 | using System;
|
2 | 2 | using System.IO;
|
3 | 3 | using System.Linq;
|
| 4 | +using System.Net.Http; |
4 | 5 | using System.Text.Encodings.Web;
|
5 | 6 | using System.Text.Unicode;
|
| 7 | +using System.Threading.Tasks; |
6 | 8 | using FluentValidation.AspNetCore;
|
7 | 9 | using GraphQL.Client.Abstractions;
|
8 | 10 | using GraphQL.Client.Http;
|
@@ -340,6 +342,8 @@ public void ConfigureServices(IServiceCollection services)
|
340 | 342 |
|
341 | 343 | services.AddProxy(builder => builder.AddHttpMessageHandler(sp => sp.GetService<AuthenticationHandlerFactory>().CreateAuthHandler()));
|
342 | 344 |
|
| 345 | + services.Configure<ProxyOptions>(options => options.WebSocketKeepAliveInterval = TimeSpan.FromSeconds(50)); |
| 346 | + |
343 | 347 | services.AddSingleton<IGraphQLClient>(s =>
|
344 | 348 | {
|
345 | 349 | var platformEndpointOptions = s.GetRequiredService<IOptions<PlatformEndpointOptions>>().Value;
|
@@ -427,16 +431,22 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
427 | 431 | });
|
428 | 432 |
|
429 | 433 | var platformEndpointOptions = app.ApplicationServices.GetRequiredService<IOptions<PlatformEndpointOptions>>().Value;
|
430 |
| - // Forwards the request only when the host is set to the specified value |
431 |
| - app.UseWhen( |
432 |
| - context => context.Request.Path.Value.EndsWith("xapi/graphql"), |
433 |
| - appInner => appInner.RunProxy(context => |
| 434 | + |
| 435 | + var httpsPlatformGraphqlEndpoint = new Uri(platformEndpointOptions.Url, "graphql"); |
| 436 | + var wssPlatformGraphqlEndpoint = new UriBuilder(httpsPlatformGraphqlEndpoint) |
| 437 | + { |
| 438 | + Scheme = httpsPlatformGraphqlEndpoint.Scheme == Uri.UriSchemeHttps ? Uri.UriSchemeWss : Uri.UriSchemeWs |
| 439 | + }.Uri; |
| 440 | + |
| 441 | + app.UseWebSockets(); |
| 442 | + app.Map("/xapi/graphql", |
| 443 | + appInner => |
434 | 444 | {
|
435 |
| - context.Request.Path = PathString.Empty; |
436 |
| - return context.ForwardTo(new Uri(platformEndpointOptions.Url, "graphql")) |
| 445 | + appInner.UseWebSocketProxy(_ => wssPlatformGraphqlEndpoint, options => options.AddXForwardedHeaders()); |
| 446 | + appInner.RunProxy(context => context.ForwardTo(httpsPlatformGraphqlEndpoint) |
437 | 447 | .AddXForwardedHeaders()
|
438 |
| - .Send(); |
439 |
| - })); |
| 448 | + .Send()); |
| 449 | + }); |
440 | 450 |
|
441 | 451 | app.UseWhen(
|
442 | 452 | context => context.Request.Path.Value.EndsWith("/token"),
|
|
0 commit comments