Skip to content

Commit

Permalink
.net 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedicht committed Jul 3, 2024
1 parent 6d9ba64 commit d291a4f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/master_besthttpwebgldemo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Set up .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.x'
dotnet-version: '8.0.x'

- name: Build with dotnet
run: dotnet build --configuration Release
Expand Down
12 changes: 6 additions & 6 deletions BestHTTP_DemoSite/BestHTTP_DemoSite.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<UserSecretsId>f4037f8b-296e-46b9-a038-f8132a344b0f</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MessagePack.UnityShims" Version="2.3.85" />
<PackageReference Include="MessagePack.UnityShims" Version="2.5.140" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.13" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="5.0.13" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Reactive.Linq" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="8.0.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Reactive.Linq" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
70 changes: 46 additions & 24 deletions BestHTTP_DemoSite/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.IO;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Primitives;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Primitives;
using Microsoft.IdentityModel.Tokens;

using Newtonsoft.Json;

using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.IO;
using System.IO.Pipelines;
using System.Net.WebSockets;
using System.Security.Claims;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace BestHTTP_DemoSite
{
public class Startup
{
private readonly SymmetricSecurityKey SecurityKey = new SymmetricSecurityKey(System.Text.Encoding.ASCII.GetBytes("Super secret security key!"));
private readonly SymmetricSecurityKey SecurityKey = new SymmetricSecurityKey(System.Text.Encoding.ASCII.GetBytes("Super secret and very, very long security key!"));
private readonly JwtSecurityTokenHandler JwtTokenHandler = new JwtSecurityTokenHandler();

public Startup(IConfiguration configuration)
Expand Down Expand Up @@ -108,13 +107,18 @@ public void ConfigureServices(IServiceCollection services)

services.AddSignalR(options =>
{
options.MaximumReceiveMessageSize = 1024 * 1024 * 1024;

options.EnableDetailedErrors = true;
//options.KeepAliveInterval = TimeSpan.FromSeconds(1);
options.MaximumParallelInvocationsPerClient = 10;
}).AddMessagePackProtocol(options =>
{
//options.SerializerOptions.
});

services.AddControllers(op =>
{
});
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand All @@ -135,7 +139,9 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
//app.UseCors("Everything");
app.UseCors(builder =>
{
builder.WithOrigins("https://localhost:4000", "https://besthttpdemosite.azurewebsites.net", "https://besthttpdemo.azureedge.net", "https://besthttpwebgldemo.azurewebsites.net", "https://benedicht.github.io")
builder
//.WithOrigins("https://localhost:4000", "https://besthttpdemosite.azurewebsites.net", "https://besthttpdemo.azureedge.net", "https://besthttpwebgldemo.azurewebsites.net", "https://benedicht.github.io")
.SetIsOriginAllowed(origin => true)
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
Expand All @@ -151,9 +157,20 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

app.UseEndpoints(endpoints =>
{
endpoints.MapHub<Hubs.TestHub>("/TestHub");
endpoints.MapHub<Hubs.HubWithAuthorization>("/HubWithAuthorization");
endpoints.MapHub<Hubs.UploadHub>("/uploading");
endpoints.MapHub<Hubs.TestHub>("/TestHub", options =>
{
options.AllowStatefulReconnects = true;
options.ApplicationMaxBufferSize = 1024 * 1024 * 1024;
options.TransportMaxBufferSize = 1024 * 1024 * 1024;
});
endpoints.MapHub<Hubs.HubWithAuthorization>("/HubWithAuthorization", options =>
{
options.AllowStatefulReconnects = true;
});
endpoints.MapHub<Hubs.UploadHub>("/uploading", options =>
{
options.AllowStatefulReconnects = true;
});
});

//app.UseSignalR(routes =>
Expand Down Expand Up @@ -241,24 +258,29 @@ await context.Response.WriteAsync(JsonConvert.SerializeObject(new
// https://stackoverflow.com/questions/36227565/aspnet-core-server-sent-events-response-flush

var response = context.Response;
response.Headers.Add("Content-Type", "text/event-stream");
response.Headers.Add("Content-Type", "text/event-stream;charset=UTF-8");

Check warning on line 261 in BestHTTP_DemoSite/Startup.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

Use IHeaderDictionary.Append or the indexer to append or set headers. IDictionary.Add will throw an ArgumentException when attempting to add a duplicate key. (https://aka.ms/aspnet/analyzers)

Check warning on line 261 in BestHTTP_DemoSite/Startup.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

Use IHeaderDictionary.Append or the indexer to append or set headers. IDictionary.Add will throw an ArgumentException when attempting to add a duplicate key. (https://aka.ms/aspnet/analyzers)

for (var i = 0; true; ++i)
{
await response.WriteAsync(": this is a comment!\r\r");
await response.WriteAsync("event: datetime\r");
await response.WriteAsync($"data: {{\"eventid\": {i}, \"datetime\": \"{DateTime.Now}\"}}\r\r");
await response.WriteAsync("data: Message from the server without an event.\r\r");
//await response.WriteAsync(": this is a comment!\r\r");
await response.WriteAsync("event: datetime\r\n");
await response.WriteAsync($"data: {{\"eventid\": {i}, \"datetime\": \"{DateTime.Now}\"}}\r\n");
//await response.WriteAsync("data: Message from the server without an event.\r");

await response.Body.FlushAsync();
await response.WriteAsync("\r\n");
await response.Body.FlushAsync();

await Task.Delay(5 * 1000);
}
}
else if (context.Request.Path == "/ws")
{
if (context.WebSockets.IsWebSocketRequest)
{
WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync();
WebSocketAcceptContext wsContext = new WebSocketAcceptContext();
wsContext.DangerousEnableCompression = true;
WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync(wsContext);
await WebSocketEcho(context, webSocket);
}
else
Expand Down

0 comments on commit d291a4f

Please sign in to comment.