Skip to content

Commit

Permalink
fix empty or string content on server http response
Browse files Browse the repository at this point in the history
  • Loading branch information
alec1o committed Dec 21, 2024
1 parent deb14ea commit 17c03cf
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/http/partials/Server/HTTP.ServerResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,23 @@ public void Send(int statusCode, string textBuffer)
{
if (!IsOpened) return;

if (!string.IsNullOrEmpty(textBuffer)) _bytes.AddRange(textBuffer.GetBytes(Encoding));
if (!string.IsNullOrEmpty(textBuffer))
{
byte[] buffer = null;

try
{
buffer = textBuffer.GetBytes(Encoding);
}
finally
{
if (buffer != null && buffer.Length > 0)
{
if (buffer.Length == 1) _bytes.Add(buffer[0]);
else _bytes.AddRange(buffer);
}
}
}

WriteAndSend(statusCode);
}
Expand Down

0 comments on commit 17c03cf

Please sign in to comment.