37 lines
945 B
C#
37 lines
945 B
C#
namespace MiniHTTP.Responses;
|
|
|
|
public class HttpResponse
|
|
{
|
|
public static implicit operator HttpResponse(HttpContent value)
|
|
{
|
|
return new OK(value);
|
|
}
|
|
|
|
public static implicit operator HttpResponse(HttpContent? value)
|
|
{
|
|
return value == null ? new NotFound() : new OK(value);
|
|
}
|
|
|
|
public readonly int StatusCode;
|
|
|
|
public readonly string StatusMessage;
|
|
|
|
public readonly HttpContent? Body;
|
|
|
|
public HttpResponse(int statusCode, string statusMessage, HttpContent? body = null)
|
|
{
|
|
StatusCode = statusCode;
|
|
StatusMessage = statusMessage;
|
|
Body = body;
|
|
}
|
|
|
|
public virtual IEnumerable<(string, string)> GetHeaders()
|
|
{
|
|
if (Body.HasValue)
|
|
{
|
|
int contentLength = Body.Value.Content.Length;
|
|
yield return ("Content-Length", contentLength.ToString());
|
|
yield return ("Content-Type", Body.Value.Type);
|
|
}
|
|
}
|
|
}
|