From 19cfd03cbf54da87a9e6e14cd4b8c5db8cff797b Mon Sep 17 00:00:00 2001 From: "Alecio Furanze (Ale)" Date: Thu, 27 Jun 2024 17:29:31 +0200 Subject: [PATCH] HTTP->ServerResponse -> improve the way of close connection HTTP->ServerResponse -> improve the way of close connection --- src/http/partials/Server/HTTP.ServerResponse.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/http/partials/Server/HTTP.ServerResponse.cs b/src/http/partials/Server/HTTP.ServerResponse.cs index 71f4273c..76ed0477 100644 --- a/src/http/partials/Server/HTTP.ServerResponse.cs +++ b/src/http/partials/Server/HTTP.ServerResponse.cs @@ -122,8 +122,18 @@ private void WriteAndSend(int statusCode) } catch (Exception e) { - // TODO: Handle it - Console.WriteLine($"{nameof(ServerRequest)} -> {nameof(Send)}: {e}"); + try + { + _response.Close(); + } + catch (Exception exception) + { + Console.WriteLine($"[#1] {nameof(ServerRequest)} -> {nameof(Send)}: {exception}"); + } + finally + { + Console.WriteLine($"[#2] {nameof(ServerRequest)} -> {nameof(Send)}: {e}"); + } } }); }