PlainTextEndpoint.cs 672 B

1234567891011121314151617181920
  1. namespace Benchmarks.Endpoints;
  2. public sealed class PlainTextEndpoint : Endpoint<EmptyRequest, EmptyResponse>
  3. {
  4. private static readonly byte[] payload = System.Text.Encoding.UTF8.GetBytes("Hello, World!");
  5. public override void Configure()
  6. {
  7. Get("/plaintext");
  8. AllowAnonymous();
  9. }
  10. public override Task HandleAsync(EmptyRequest _, CancellationToken __)
  11. {
  12. HttpContext.Response.StatusCode = StatusCodes.Status200OK;
  13. HttpContext.Response.ContentType = "text/plain";
  14. HttpContext.Response.ContentLength = payload.Length;
  15. return HttpContext.Response.Body.WriteAsync(payload, 0, payload.Length);
  16. }
  17. }