Compare commits

...

2 commits

Author SHA1 Message Date
uwaa
b118c1cd30 fix HTTP response generator methods 2024-11-24 07:46:13 +00:00
uwaa
8dfedea393 http: move FieldCallback 2024-11-24 07:45:54 +00:00
2 changed files with 12 additions and 16 deletions

View file

@ -173,6 +173,8 @@ public record HttpFields
}
}
public delegate void FieldCallback(string name, string value);
public enum ConnectionType
{
Close,

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;
@ -116,5 +112,3 @@ public class HttpResponse
await stream.Flush();
}
}
public delegate void FieldCallback(string name, string value);