Compare commits
2 commits
ce757177c6
...
b118c1cd30
Author | SHA1 | Date | |
---|---|---|---|
|
b118c1cd30 | ||
|
8dfedea393 |
2 changed files with 12 additions and 16 deletions
|
@ -173,6 +173,8 @@ public record HttpFields
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public delegate void FieldCallback(string name, string value);
|
||||||
|
|
||||||
public enum ConnectionType
|
public enum ConnectionType
|
||||||
{
|
{
|
||||||
Close,
|
Close,
|
||||||
|
|
|
@ -25,27 +25,23 @@ public class SwitchingProtocols : HttpResponse
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class 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 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;
|
public readonly int StatusCode;
|
||||||
|
|
||||||
|
@ -115,6 +111,4 @@ public class HttpResponse
|
||||||
|
|
||||||
await stream.Flush();
|
await stream.Flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate void FieldCallback(string name, string value);
|
|
Loading…
Reference in a new issue