-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b67d2d
commit a602f0b
Showing
3 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/TestHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters