From b118c1cd3004e494a2bb1e285e7488903e6356f5 Mon Sep 17 00:00:00 2001 From: uwaa Date: Sun, 24 Nov 2024 07:46:13 +0000 Subject: [PATCH] fix HTTP response generator methods --- HTTP/HttpResponse.cs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/HTTP/HttpResponse.cs b/HTTP/HttpResponse.cs index 0b68de1..ab3d34e 100644 --- a/HTTP/HttpResponse.cs +++ b/HTTP/HttpResponse.cs @@ -25,27 +25,23 @@ public class SwitchingProtocols : HttpResponse /// 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;