mon_service_http_request.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "mon_service_http_request.h"
  2. #include "monservice.h"
  3. using namespace NMonitoring;
  4. IMonHttpRequest::~IMonHttpRequest() {
  5. }
  6. TMonService2HttpRequest::~TMonService2HttpRequest() {
  7. }
  8. TString TMonService2HttpRequest::GetServiceTitle() const {
  9. return MonService->GetTitle();
  10. }
  11. IOutputStream& TMonService2HttpRequest::Output() {
  12. return *Out;
  13. }
  14. HTTP_METHOD TMonService2HttpRequest::GetMethod() const {
  15. return HttpRequest->GetMethod();
  16. }
  17. TStringBuf TMonService2HttpRequest::GetPathInfo() const {
  18. return PathInfo;
  19. }
  20. TStringBuf TMonService2HttpRequest::GetPath() const {
  21. return HttpRequest->GetPath();
  22. }
  23. TStringBuf TMonService2HttpRequest::GetUri() const {
  24. return HttpRequest->GetURI();
  25. }
  26. const TCgiParameters& TMonService2HttpRequest::GetParams() const {
  27. return HttpRequest->GetParams();
  28. }
  29. const TCgiParameters& TMonService2HttpRequest::GetPostParams() const {
  30. return HttpRequest->GetPostParams();
  31. }
  32. TStringBuf TMonService2HttpRequest::GetHeader(TStringBuf name) const {
  33. const THttpHeaders& headers = HttpRequest->GetHeaders();
  34. const THttpInputHeader* header = headers.FindHeader(name);
  35. if (header != nullptr) {
  36. return header->Value();
  37. }
  38. return TStringBuf();
  39. }
  40. const THttpHeaders& TMonService2HttpRequest::GetHeaders() const {
  41. return HttpRequest->GetHeaders();
  42. }
  43. TString TMonService2HttpRequest::GetRemoteAddr() const {
  44. return HttpRequest->GetRemoteAddr();
  45. }
  46. TStringBuf TMonService2HttpRequest::GetCookie(TStringBuf name) const {
  47. TStringBuf cookie = GetHeader("Cookie");
  48. size_t size = cookie.size();
  49. size_t start = 0;
  50. while (start < size) {
  51. size_t semicolon = cookie.find(';', start);
  52. auto pair = cookie.substr(start, semicolon - start);
  53. if (!pair.empty()) {
  54. size_t equal = pair.find('=');
  55. if (equal != TStringBuf::npos) {
  56. auto cookieName = pair.substr(0, equal);
  57. if (cookieName == name) {
  58. size_t valueStart = equal + 1;
  59. auto cookieValue = pair.substr(valueStart, semicolon - valueStart);
  60. return cookieValue;
  61. }
  62. }
  63. start = semicolon;
  64. while (start < size && (cookie[start] == ' ' || cookie[start] == ';')) {
  65. ++start;
  66. }
  67. }
  68. }
  69. return TStringBuf();
  70. }