Skip to content

Commit

Permalink
missing md5 test
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara committed May 12, 2021
1 parent 7b67d2d commit a602f0b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public async Task Invoke(HttpContext context)
await EchoWebSocketHeadersHandler.InvokeAsync(context);
return;
}
if (path.Equals(new PathString("/test.ashx")))
{
await TestHandler.InvokeAsync(context);
return;
}

// Default handling.
await EchoHandler.InvokeAsync(context);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;

namespace NetCoreServer
{
public class TestHandler
{
public static async Task InvokeAsync(HttpContext context)
{
RequestInformation info = await RequestInformation.CreateAsync(context.Request);

string echoJson = info.SerializeToJson();

// Compute MD5 hash to clients can verify the received data.
MD5 md5 = MD5.Create();
byte[] bytes = Encoding.ASCII.GetBytes(echoJson);
var hash = md5.ComputeHash(bytes);
string encodedHash = Convert.ToBase64String(hash);
context.Response.Headers.Add("Content-MD5", encodedHash);

RequestInformation newEcho = RequestInformation.DeSerializeFromJson(echoJson);
context.Response.ContentType = "text/plain"; //"application/json";
await context.Response.WriteAsync(echoJson);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,33 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<OutputType>Exe</OutputType>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

<ItemGroup>
<Folder Include="Handlers\" />
<Folder Include="Helpers\" />
<Compile Include="Handlers\DeflateHandler.cs" />
<Compile Include="Handlers\EchoHandler.cs" />
<Compile Include="Handlers\EchoWebSocketHandler.cs" />
<Compile Include="Handlers\EchoWebSocketHeadersHandler.cs" />
<Compile Include="Handlers\EmptyContentHandler.cs" />
<Compile Include="Handlers\GZipHandler.cs" />
<Compile Include="Handlers\RedirectHandler.cs" />
<Compile Include="Handlers\StatusCodeHandler.cs" />
<Compile Include="Handlers\TestHandler.cs" />
<Compile Include="Handlers\VerifyUploadHandler.cs" />
<Compile Include="Handlers\VersionHandler.cs" />
<Compile Include="Helpers\AuthenticationHelper.cs" />
<Compile Include="Helpers\ContentHelper.cs" />
<Compile Include="Helpers\NameValueCollectionConverter.cs" />
<Compile Include="Helpers\RequestHelper.cs" />
<Compile Include="Helpers\RequestInformation.cs" />
<Compile Include="GenericHandler.cs" />
<Compile Include="Program.cs" />
<Compile Include="Startup.cs" />
</ItemGroup>

</Project>

0 comments on commit a602f0b

Please sign in to comment.