fix HTTP response generator methods

This commit is contained in:
uwaa 2024-11-24 07:46:13 +00:00
parent 8dfedea393
commit b118c1cd30

View file

@ -25,27 +25,23 @@ public class SwitchingProtocols : HttpResponse
/// </summary>
public class HttpResponse
{
public static HttpResponse OK(HttpContent? content) => new HttpResponse(200, "OK", content);
public static HttpResponse OK(HttpContent? content = null) => new HttpResponse(200, "OK", content);
public static HttpResponse Redirect(string location) => new HttpResponse(301, "Redirect", new HttpFields() { Location = location });
public static HttpResponse BadRequest(HttpContent? content) => new HttpResponse(400, "Bad request", content);
public static HttpResponse BadRequest(HttpContent? content = null) => new HttpResponse(400, "Bad request", content);
public static HttpResponse NotFound(HttpContent? content) => new HttpResponse(404, "Not found", content);
public static HttpResponse NotFound(HttpContent? content = null) => new HttpResponse(404, "Not found", content);
public static HttpResponse NotAcceptable(HttpContent? content) => new HttpResponse(406, "Not acceptable", content);
public static HttpResponse NotAcceptable(HttpContent? content = null) => new HttpResponse(406, "Not acceptable", content);
public static HttpResponse InternalServerError(string location) => new HttpResponse(500, "Internal server error");
public static HttpResponse InternalServerError(HttpContent? content = null) => new HttpResponse(500, "Internal server error", content);
public static implicit operator HttpResponse(HttpContent value) => OK(value);
public static implicit operator HttpResponse(HttpContent? value) => value == null ? NotFound(value) : OK(value);
public static implicit operator HttpResponse(HttpContent value)
{
return OK(value);
}
public static implicit operator HttpResponse(HttpContent? value)
{
return value == null ? NotFound(value) : OK(value);
}
public readonly int StatusCode;