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 
17 #ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_SERVICEREQUEST_H_
18 #define CORE_INCLUDE_ALIBABACLOUD_CORE_SERVICEREQUEST_H_
19 
20 #include "CoreExport.h"
21 #include "HttpRequest.h"
22 #include "Url.h"
23 #include <map>
24 #include <string>
25 
26 namespace AlibabaCloud {
27 class ALIBABACLOUD_CORE_EXPORT ServiceRequest {
28 public:
29   typedef std::string ParameterNameType;
30   typedef std::string ParameterValueType;
31   typedef std::map<ParameterNameType, ParameterValueType> ParameterCollection;
32 
33   virtual ~ServiceRequest();
34 
35   const char *content() const;
36   size_t contentSize() const;
37   bool hasContent() const;
38   ParameterCollection parameters() const;
39   ParameterCollection bodyParameters() const;
40   std::string product() const;
41   std::string resourcePath() const;
42   std::string version() const;
43   std::string scheme() const;
44   HttpRequest::Method method() const;
45   long connectTimeout() const;
46   long readTimeout() const;
47   void setConnectTimeout(const long connectTimeout);
48   void setReadTimeout(const long readTimeout);
49   void setMethod(const HttpRequest::Method method);
50   void setHeader(const ParameterNameType &name,
51                  const ParameterValueType &value);
52   ParameterValueType getHeader(const ParameterNameType &name);
53   void removeHeader(const ParameterNameType &name);
54   ParameterCollection headers() const;
55   void setBodyParameter(const ParameterNameType &name,
56                         const ParameterValueType &value);
57 
58 protected:
59   ServiceRequest(const std::string &product, const std::string &version);
60   ServiceRequest(const ServiceRequest &other);
61   ServiceRequest(ServiceRequest &&other);
62   ServiceRequest &operator=(const ServiceRequest &other);
63   ServiceRequest &operator=(ServiceRequest &&other);
64 
65   void addParameter(const ParameterNameType &name,
66                     const ParameterValueType &value);
67   ParameterValueType parameter(const ParameterNameType &name) const;
68   ParameterValueType coreParameter(const ParameterNameType &name) const;
69   void removeParameter(const ParameterNameType &name);
70   void setContent(const char *data, size_t size);
71   void setParameter(const ParameterNameType &name,
72                     const ParameterValueType &value);
73 
74   void setCoreParameter(const ParameterNameType &name,
75                         const ParameterValueType &value);
76 
77   void setParameters(const ParameterCollection &params);
78   void setJsonParameters(const ParameterNameType &name,
79                          const ParameterCollection &params);
80   void setResourcePath(const std::string &path);
81   void setProduct(const std::string &product);
82   void setVersion(const std::string &version);
83   void setScheme(const std::string scheme);
84 
85 private:
86   char *content_;
87   size_t contentSize_;
88   ParameterCollection params_;
89   ParameterCollection body_params_;
90   ParameterCollection headers_;
91   std::string product_;
92   std::string resourcePath_;
93   std::string version_;
94   std::string scheme_;
95   long connectTimeout_;
96   long readTimeout_;
97   HttpRequest::Method method_;
98 };
99 } // namespace AlibabaCloud
100 
101 #endif // CORE_INCLUDE_ALIBABACLOUD_CORE_SERVICEREQUEST_H_
102