mon_service_http_request.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #include "service.h"
  3. #include <util/stream/output.h>
  4. namespace NMonitoring {
  5. class TMonService2;
  6. class IMonPage;
  7. // XXX: IHttpRequest is already taken
  8. struct IMonHttpRequest {
  9. virtual ~IMonHttpRequest();
  10. virtual IOutputStream& Output() = 0;
  11. virtual HTTP_METHOD GetMethod() const = 0;
  12. virtual TStringBuf GetPath() const = 0;
  13. virtual TStringBuf GetPathInfo() const = 0;
  14. virtual TStringBuf GetUri() const = 0;
  15. virtual const TCgiParameters& GetParams() const = 0;
  16. virtual const TCgiParameters& GetPostParams() const = 0;
  17. virtual TStringBuf GetPostContent() const = 0;
  18. virtual const THttpHeaders& GetHeaders() const = 0;
  19. virtual TStringBuf GetHeader(TStringBuf name) const = 0;
  20. virtual TStringBuf GetCookie(TStringBuf name) const = 0;
  21. virtual TString GetRemoteAddr() const = 0;
  22. virtual TString GetServiceTitle() const = 0;
  23. virtual IMonPage* GetPage() const = 0;
  24. virtual IMonHttpRequest* MakeChild(IMonPage* page, const TString& pathInfo) const = 0;
  25. };
  26. struct TMonService2HttpRequest: IMonHttpRequest {
  27. IOutputStream* const Out;
  28. const IHttpRequest* const HttpRequest;
  29. TMonService2* const MonService;
  30. IMonPage* const MonPage;
  31. const TString PathInfo;
  32. TMonService2HttpRequest* const Parent;
  33. TMonService2HttpRequest(
  34. IOutputStream* out, const IHttpRequest* httpRequest,
  35. TMonService2* monService, IMonPage* monPage,
  36. const TString& pathInfo,
  37. TMonService2HttpRequest* parent)
  38. : Out(out)
  39. , HttpRequest(httpRequest)
  40. , MonService(monService)
  41. , MonPage(monPage)
  42. , PathInfo(pathInfo)
  43. , Parent(parent)
  44. {
  45. }
  46. ~TMonService2HttpRequest() override;
  47. IOutputStream& Output() override;
  48. HTTP_METHOD GetMethod() const override;
  49. TStringBuf GetPath() const override;
  50. TStringBuf GetPathInfo() const override;
  51. TStringBuf GetUri() const override;
  52. const TCgiParameters& GetParams() const override;
  53. const TCgiParameters& GetPostParams() const override;
  54. TStringBuf GetPostContent() const override {
  55. return HttpRequest->GetPostContent();
  56. }
  57. TStringBuf GetHeader(TStringBuf name) const override;
  58. TStringBuf GetCookie(TStringBuf name) const override;
  59. const THttpHeaders& GetHeaders() const override;
  60. TString GetRemoteAddr() const override;
  61. IMonPage* GetPage() const override {
  62. return MonPage;
  63. }
  64. TMonService2HttpRequest* MakeChild(IMonPage* page, const TString& pathInfo) const override {
  65. return new TMonService2HttpRequest{
  66. Out, HttpRequest, MonService, page,
  67. pathInfo, const_cast<TMonService2HttpRequest*>(this)
  68. };
  69. }
  70. TString GetServiceTitle() const override;
  71. };
  72. }