• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef COMMUNICATIONNETSTACK_HTTP_REQUEST_OPTIONS_H
17 #define COMMUNICATIONNETSTACK_HTTP_REQUEST_OPTIONS_H
18 
19 #include <map>
20 #include <string>
21 
22 #include "constant.h"
23 
24 namespace OHOS::NetStack::Http {
25 enum class HttpProtocol {
26     HTTP1_1,
27     HTTP2,
28     HTTP_NONE, // default choose by curl
29 };
30 
31 enum class UsingHttpProxyType {
32     NOT_USE,
33     USE_DEFAULT,
34     USE_SPECIFIED,
35 };
36 
37 class HttpRequestOptions final {
38 public:
39     HttpRequestOptions();
40 
41     void SetUrl(const std::string &url);
42 
43     void SetMethod(const std::string &method);
44 
45     void SetBody(const void *data, size_t length);
46 
47     void SetHeader(const std::string &key, const std::string &val);
48 
49     void SetReadTimeout(uint32_t readTimeout);
50 
51     void SetConnectTimeout(uint32_t connectTimeout);
52 
53     void SetUsingProtocol(HttpProtocol httpProtocol);
54 
55     void SetHttpDataType(HttpDataType dataType);
56 
57     void SetUsingHttpProxyType(UsingHttpProxyType type);
58 
59     void SetSpecifiedHttpProxy(const std::string &host, int32_t port, const std::string &exclusionList);
60 
61     void SetCaPath(const std::string &SetCaPath);
62 
63     [[nodiscard]] const std::string &GetUrl() const;
64 
65     [[nodiscard]] const std::string &GetMethod() const;
66 
67     [[nodiscard]] const std::string &GetBody() const;
68 
69     [[nodiscard]] const std::map<std::string, std::string> &GetHeader() const;
70 
71     [[nodiscard]] uint32_t GetReadTimeout() const;
72 
73     [[nodiscard]] uint32_t GetConnectTimeout() const;
74 
75     [[nodiscard]] uint32_t GetHttpVersion() const;
76 
77     void SetRequestTime(const std::string &time);
78 
79     [[nodiscard]] const std::string &GetRequestTime() const;
80 
81     [[nodiscard]] HttpDataType GetHttpDataType() const;
82 
83     void SetPriority(uint32_t priority);
84 
85     [[nodiscard]] uint32_t GetPriority() const;
86 
87     [[nodiscard]] UsingHttpProxyType GetUsingHttpProxyType() const;
88 
89     void GetSpecifiedHttpProxy(std::string &host, int32_t &port, std::string &exclusionList);
90 
91     [[nodiscard]] const std::string &GetCaPath() const;
92 
93 private:
94     std::string url_;
95 
96     std::string body_;
97 
98     std::string method_;
99 
100     std::map<std::string, std::string> header_;
101 
102     uint32_t readTimeout_;
103 
104     uint32_t connectTimeout_;
105 
106     HttpProtocol usingProtocol_;
107 
108     std::string requestTime_;
109 
110     HttpDataType dataType_;
111 
112     uint32_t priority_;
113 
114     UsingHttpProxyType usingHttpProxyType_;
115 
116     std::string httpProxyHost_;
117 
118     int32_t httpProxyPort_;
119 
120     std::string httpProxyExclusions_;
121 
122     std::string caPath_;
123 };
124 } // namespace OHOS::NetStack::Http
125 
126 #endif /* COMMUNICATIONNETSTACK_HTTP_REQUEST_OPTIONS_H */
127