ServerHeaderConcern.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using GenHTTP.Api.Content;
  5. using GenHTTP.Api.Protocol;
  6. namespace Benchmarks.Utilities
  7. {
  8. public sealed class ServerHeaderConcern : IConcern
  9. {
  10. #region Get-/Setters
  11. public IHandler Content { get; }
  12. public IHandler Parent { get; }
  13. #endregion
  14. #region Initialization
  15. public ServerHeaderConcern(IHandler parent, Func<IHandler, IHandler> contentFactory)
  16. {
  17. Parent = parent;
  18. Content = contentFactory(this);
  19. }
  20. #endregion
  21. #region Functionality
  22. public IEnumerable<ContentElement> GetContent(IRequest request) => Content.GetContent(request);
  23. public ValueTask PrepareAsync() => Content.PrepareAsync();
  24. public async ValueTask<IResponse> HandleAsync(IRequest request)
  25. {
  26. var response = await Content.HandleAsync(request);
  27. if (response != null)
  28. {
  29. response.Headers.Add("Server", "TFB");
  30. }
  31. return response;
  32. }
  33. #endregion
  34. }
  35. }