• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 {
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     [[nodiscard]] const std::string &GetUrl() const;
62 
63     [[nodiscard]] const std::string &GetMethod() const;
64 
65     [[nodiscard]] const std::string &GetBody() const;
66 
67     [[nodiscard]] const std::map<std::string, std::string> &GetHeader() const;
68 
69     [[nodiscard]] uint32_t GetReadTimeout() const;
70 
71     [[nodiscard]] uint32_t GetConnectTimeout() const;
72 
73     [[nodiscard]] uint32_t GetHttpVersion() const;
74 
75     void SetRequestTime(const std::string &time);
76 
77     [[nodiscard]] const std::string &GetRequestTime() const;
78 
79     [[nodiscard]] HttpDataType GetHttpDataType() const;
80 
81     void SetPriority(uint32_t priority);
82 
83     [[nodiscard]] uint32_t GetPriority() const;
84 
85     [[nodiscard]] UsingHttpProxyType GetUsingHttpProxyType() const;
86 
87     void GetSpecifiedHttpProxy(std::string &host, int32_t &port, std::string &exclusionList);
88 
89 private:
90     std::string url_;
91 
92     std::string body_;
93 
94     std::string method_;
95 
96     std::map<std::string, std::string> header_;
97 
98     uint32_t readTimeout_;
99 
100     uint32_t connectTimeout_;
101 
102     HttpProtocol usingProtocol_;
103 
104     std::string requestTime_;
105 
106     HttpDataType dataType_;
107 
108     uint32_t priority_;
109 
110     UsingHttpProxyType usingHttpProxyType_;
111 
112     std::string httpProxyHost_;
113 
114     int32_t httpProxyPort_;
115 
116     std::string httpProxyExclusions_;
117 };
118 } // namespace OHOS::NetStack
119 
120 #endif /* COMMUNICATIONNETSTACK_HTTP_REQUEST_OPTIONS_H */
121