Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/Console/Interactive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,16 @@ async Task InputListener()
{
AnsiConsole.MarkupLine($"[red] Failed to send message.[/] [bold]Status Code:[/] {response.StatusCode}");
}

AnsiConsole.Markup($":person_beard: ");
needsNewline = true;
}
catch (Exception e)
{
AnsiConsole.WriteException(e);
}
finally
{
AnsiConsole.Markup($":person_beard: ");
needsNewline = true;
}
}
}
}
Expand All @@ -126,12 +128,11 @@ async Task ResponseListener()
while (!cts.IsCancellationRequested)
{
var context = await listener!.GetContextAsync();
var request = context.Request;
var response = context.Response;

try
{
var request = context.Request;
var response = context.Response;

// Read the request body (if any)
var requestBody = "{}";
using (var reader = new StreamReader(request.InputStream, request.ContentEncoding))
Expand All @@ -140,20 +141,22 @@ async Task ResponseListener()
}

await RenderAsync(requestBody);

var buffer = Encoding.UTF8.GetBytes("OK");
response.ContentLength64 = buffer.Length;
response.ContentType = "text/plain";

await response.OutputStream.WriteAsync(buffer);
response.OutputStream.Close();
}
catch (Exception ex)
{
Console.WriteLine($"Error processing request: {ex.Message}");
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
context.Response.Close();
}
finally
{
var buffer = Encoding.UTF8.GetBytes("OK");
response.ContentLength64 = buffer.Length;
response.ContentType = "text/plain";

await response.OutputStream.WriteAsync(buffer);
response.OutputStream.Close();
}
}
}

Expand Down
9 changes: 1 addition & 8 deletions src/Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,7 @@
host.Configuration.AddUserSecrets<Program>();

var http = host.Services.AddHttpClient("whatsapp");
if (Debugger.IsAttached)
{
http.ConfigureHttpClient(http => http.Timeout = TimeSpan.FromHours(1));
}
else
{
http.AddStandardResilienceHandler();
}
http.ConfigureHttpClient(http => http.Timeout = TimeSpan.FromMinutes(30));

var cts = new CancellationTokenSource();
Console.CancelKeyPress += (s, e) => cts.Cancel();
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"Console": {
"commandName": "Project",
"commandLineArgs": "-h"
"commandLineArgs": ""
}
}
}