This repository has been archived on 2023-03-22. You can view files and clone it, but cannot push or open issues or pull requests.
cuipod/Cuipod/Response.cs
Egidijus Lileika b74707aac8 Added logging support and refactored some code
Log4J vuln inspired me to add some logging to this project :)))
2021-12-15 16:46:43 +02:00

53 lines
1.3 KiB
C#

using System;
using System.IO;
using System.Text;
namespace Cuipod
{
public class Response
{
public StatusCode Status { get; set; }
private readonly string _directoryToServe;
private string _requestBody = "";
internal Response(string directoryToServe)
{
_directoryToServe = directoryToServe;
Status = StatusCode.Success;
}
public void RenderPlainTextLine(string text)
{
_requestBody += text + "\r\n";
}
public void RenderFileContent(string relativePathToFile)
{
_requestBody += File.ReadAllText(_directoryToServe + relativePathToFile, Encoding.UTF8) + "\r\n";
}
public void SetRedirectURL(string route)
{
_requestBody = route + "\r\n";
}
public void SetInputHint(string hint)
{
_requestBody = hint + "\r\n";
}
internal byte[] Encode()
{
string wholeResponse = ((int)Status).ToString() + " ";
if (Status == StatusCode.Success)
{
wholeResponse += "text/gemini\r\n";
}
wholeResponse += _requestBody;
return Encoding.UTF8.GetBytes(wholeResponse);
}
}
}