ServiceRequest.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. #include <alibabacloud/core/ServiceRequest.h>
  17. using namespace AlibabaCloud;
  18. ServiceRequest::ServiceRequest(const std::string &product, const std::string &version) :
  19. content_(nullptr),
  20. contentSize_(0),
  21. params_(),
  22. product_(product),
  23. resourcePath_("/"),
  24. version_(version),
  25. scheme_("https")
  26. {
  27. }
  28. ServiceRequest::ServiceRequest(const ServiceRequest &other) :
  29. content_(nullptr),
  30. contentSize_(other.contentSize_),
  31. params_(other.params_),
  32. product_(other.product_),
  33. resourcePath_(other.resourcePath_),
  34. version_(other.version_),
  35. scheme_(other.scheme_)
  36. {
  37. setContent(other.content_, other.contentSize_);
  38. }
  39. ServiceRequest::ServiceRequest(ServiceRequest &&other)
  40. {
  41. *this = std::move(other);
  42. }
  43. ServiceRequest& ServiceRequest::operator=(const ServiceRequest &other)
  44. {
  45. if (this != &other) {
  46. content_ = nullptr;
  47. contentSize_ = 0;
  48. params_ = other.params_;
  49. setContent(other.content_, other.contentSize_);
  50. }
  51. return *this;
  52. }
  53. ServiceRequest& ServiceRequest::operator=(ServiceRequest &&other)
  54. {
  55. if (this != &other)
  56. *this = std::move(other);
  57. return *this;
  58. }
  59. ServiceRequest::~ServiceRequest()
  60. {
  61. if (content_)
  62. delete content_;
  63. }
  64. const char * ServiceRequest::content() const
  65. {
  66. return content_;
  67. }
  68. size_t ServiceRequest::contentSize() const
  69. {
  70. return contentSize_;
  71. }
  72. bool ServiceRequest::hasContent() const
  73. {
  74. return (contentSize_ != 0);
  75. }
  76. void ServiceRequest::setContent(const char * data, size_t size)
  77. {
  78. if (content_)
  79. delete content_;
  80. content_ = nullptr;
  81. contentSize_ = 0;
  82. if (size) {
  83. contentSize_ = size;
  84. content_ = new char[size];
  85. std::copy(data, data + size, content_);
  86. }
  87. }
  88. void ServiceRequest::addParameter(const ParameterNameType & name, const ParameterValueType & value)
  89. {
  90. setParameter(name, value);
  91. }
  92. ServiceRequest::ParameterValueType ServiceRequest::parameter(const ParameterNameType &name)const
  93. {
  94. ParameterCollection::const_iterator it = params_.find(name);
  95. if (it == params_.end()) {
  96. return ParameterValueType("");
  97. }
  98. return it->second;
  99. }
  100. ServiceRequest::ParameterCollection ServiceRequest::parameters() const
  101. {
  102. return params_;
  103. }
  104. void ServiceRequest::removeParameter(const ParameterNameType & name)
  105. {
  106. params_.erase(name);
  107. }
  108. void ServiceRequest::setParameter(const ParameterNameType &name, const ParameterValueType &value)
  109. {
  110. params_[name] = value;
  111. }
  112. void ServiceRequest::setParameters(const ParameterCollection & params)
  113. {
  114. params_ = params;
  115. }
  116. std::string ServiceRequest::version()const
  117. {
  118. return version_;
  119. }
  120. void ServiceRequest::setVersion(const std::string &version)
  121. {
  122. version_ = version;
  123. }
  124. std::string ServiceRequest::product() const
  125. {
  126. return product_;
  127. }
  128. void ServiceRequest::setProduct(const std::string & product)
  129. {
  130. product_ = product;
  131. }
  132. std::string ServiceRequest::resourcePath() const
  133. {
  134. return resourcePath_;
  135. }
  136. void ServiceRequest::setResourcePath(const std::string & path)
  137. {
  138. resourcePath_ = path;
  139. }
  140. void ServiceRequest::setScheme(const std::string scheme) {
  141. scheme_ = scheme;
  142. }
  143. std::string ServiceRequest::scheme() const {
  144. return scheme_;
  145. }