ServiceRequest.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright 1999-2019 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_SERVICEREQUEST_H_
  17. #define CORE_INCLUDE_ALIBABACLOUD_CORE_SERVICEREQUEST_H_
  18. #include "CoreExport.h"
  19. #include "Url.h"
  20. #include <map>
  21. #include <string>
  22. #include "HttpRequest.h"
  23. namespace AlibabaCloud {
  24. class ALIBABACLOUD_CORE_EXPORT ServiceRequest {
  25. public:
  26. typedef std::string ParameterNameType;
  27. typedef std::string ParameterValueType;
  28. typedef std::map<ParameterNameType, ParameterValueType> ParameterCollection;
  29. virtual ~ServiceRequest();
  30. const char *content() const;
  31. size_t contentSize() const;
  32. bool hasContent() const;
  33. ParameterCollection parameters() const;
  34. std::string product() const;
  35. std::string resourcePath() const;
  36. std::string version() const;
  37. std::string scheme() const;
  38. HttpRequest::Method method() const;
  39. long connectTimeout() const;
  40. long readTimeout() const;
  41. void setConnectTimeout(const long connectTimeout);
  42. void setReadTimeout(const long readTimeout);
  43. void setMethod(const HttpRequest::Method method);
  44. void setHeader(const ParameterNameType &name, const ParameterValueType &value);
  45. ParameterValueType getHeader(const ParameterNameType &name);
  46. void removeHeader(const ParameterNameType &name);
  47. ParameterCollection headers() const;
  48. protected:
  49. ServiceRequest(const std::string &product, const std::string &version);
  50. ServiceRequest(const ServiceRequest &other);
  51. ServiceRequest(ServiceRequest &&other);
  52. ServiceRequest &operator=(const ServiceRequest &other);
  53. ServiceRequest &operator=(ServiceRequest &&other);
  54. void addParameter(const ParameterNameType &name,
  55. const ParameterValueType &value);
  56. ParameterValueType parameter(const ParameterNameType &name) const;
  57. ParameterValueType coreParameter(const ParameterNameType &name) const;
  58. void removeParameter(const ParameterNameType &name);
  59. void setContent(const char *data, size_t size);
  60. void setParameter(const ParameterNameType &name,
  61. const ParameterValueType &value);
  62. void setCoreParameter(const ParameterNameType &name,
  63. const ParameterValueType &value);
  64. void setParameters(const ParameterCollection &params);
  65. void setJsonParameters(const ParameterNameType &name, const ParameterCollection &params);
  66. void setResourcePath(const std::string &path);
  67. void setProduct(const std::string &product);
  68. void setVersion(const std::string &version);
  69. void setScheme(const std::string scheme);
  70. private:
  71. char *content_;
  72. size_t contentSize_;
  73. ParameterCollection params_;
  74. ParameterCollection headers_;
  75. std::string product_;
  76. std::string resourcePath_;
  77. std::string version_;
  78. std::string scheme_;
  79. long connectTimeout_;
  80. long readTimeout_;
  81. HttpRequest::Method method_;
  82. };
  83. } // namespace AlibabaCloud
  84. #endif // CORE_INCLUDE_ALIBABACLOUD_CORE_SERVICEREQUEST_H_