Skip to content

Commit

Permalink
Merge pull request #18 from Ali-YousefiTelori/develop
Browse files Browse the repository at this point in the history
Fix work on linux
  • Loading branch information
Ali-YousefiTelori authored Oct 26, 2023
2 parents f6c8a0a + 6d3a43c commit 31b4746
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ public abstract class BaseHandlerTest
public HttpClient GetHttpClient()
{
HttpClient httpClient = default;
// if (System.Environment.OSVersion.Platform != PlatformID.Unix)
// {
//#if (NET452)
// httpClient = new HttpClient();
//#else
// var handler = new WinHttpHandler();
// httpClient = new HttpClient(handler);
//#endif
// }
// else
httpClient = new HttpClient();
// if (System.Environment.OSVersion.Platform != PlatformID.Unix)
// {
//#if (NET452)
// httpClient = new HttpClient();
//#else
// var handler = new WinHttpHandler();
// httpClient = new HttpClient(handler);
//#endif
// }
// else
httpClient = new HttpClient();

#if (!NET452 && !NET48)
httpClient.DefaultRequestVersion = HttpVersion.Version20;
Expand Down Expand Up @@ -86,7 +86,7 @@ public async Task ConcurrentCheckSimpleRequestAndResponse(string request, string
var port = await GetHandler(resourceManager).Start();

List<Task<bool>> all = new List<Task<bool>>();
for (int i = 0; i < 100; i++)
for (int i = 0; i < 10; i++)
{
all.Add(Task.Run(async () =>
{
Expand Down Expand Up @@ -115,7 +115,7 @@ public async Task ConcurrentSingleHttpClientCheckSimpleRequestAndResponse(string
HttpClient httpClient = GetHttpClient();

List<Task<bool>> all = new List<Task<bool>>();
for (int i = 0; i < 20; i++)
for (int i = 0; i < 5; i++)
{
all.Add(Task.Run(async () =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class HostHttpHandlerTest : BaseHandlerTest
{
protected override BaseHandler GetHandler(ResourceManager resourceManager)
{
return BaseHandler.CreateOSHandler(resourceManager);
return new HostHttpHandler(resourceManager);
//return BaseHandler.CreateOSHandler(resourceManager);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class HttpHandlerTest : BaseHandlerTest
{
protected override BaseHandler GetHandler(ResourceManager resourceManager)
{
return BaseHandler.CreateOSHandler(resourceManager);
return new HttpHandler(resourceManager);
//return BaseHandler.CreateOSHandler(resourceManager);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if(NET6_0_OR_GREATER)
#if (NET6_0_OR_GREATER)
using Microsoft.AspNetCore.Http;
using System;
using System.IO;
Expand Down Expand Up @@ -29,7 +29,7 @@ public HostHttpHandler(ResourceManager resourceManager) : base(resourceManager)
/// <param name="httpClient"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
protected override async Task HandleHttpClient(HttpContext httpClient)
protected override async Task<bool> HandleHttpClient(HttpContext httpClient)
{
var reader = new StreamReader(httpClient.Request.Body);
var requestBody = await reader.ReadToEndAsync();
Expand Down Expand Up @@ -63,6 +63,7 @@ protected override async Task HandleHttpClient(HttpContext httpClient)

await httpClient.Response.Body.WriteAsync(bytes, 0, bytes.Length);
}
return true;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ public override void Stop()
protected virtual async Task InternalStart(int port)
{
var builder = WebApplication.CreateBuilder();
builder.WebHost.UseUrls($"http://*:{port}");
builder.WebHost
.UseUrls($"http://*:{port}")
.UseKestrel();
var app = builder.Build();
app.Use(async (context, next) =>
{
await HandleHttpClient(context);
await next(context);
if (!await HandleHttpClient(context))
await next(context);
});
await Task.WhenAny(app.RunAsync(null), Task.Delay(3000));
}
Expand All @@ -90,7 +92,7 @@ protected virtual async Task InternalStart(int port)
/// </summary>
/// <param name="httpClient"></param>
/// <returns></returns>
protected abstract Task HandleHttpClient(HttpContext httpClient);
protected abstract Task<bool> HandleHttpClient(HttpContext httpClient);

string _lastResponseBody = "";
/// <summary>
Expand Down

0 comments on commit 31b4746

Please sign in to comment.