• 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_RESPONSE_H
17 #define COMMUNICATIONNETSTACK_HTTP_RESPONSE_H
18 
19 #include <map>
20 #include <string>
21 
22 namespace OHOS::NetStack {
23 static constexpr const char *WARNING = "Warning";
24 
25 class HttpResponse final {
26 public:
27     HttpResponse();
28 
29     void AppendResult(const void *data, size_t length);
30 
31     void AppendRawHeader(const void *data, size_t length);
32 
33     void SetRawHeader(const std::string &header);
34 
35     void SetResponseCode(uint32_t responseCode);
36 
37     void ParseHeaders();
38 
39     void SetResult(const std::string &res);
40 
41     void SetCookies(const std::string &cookies);
42 
43     void AppendCookies(const void *data, size_t length);
44 
45     [[nodiscard]] const std::string &GetResult() const;
46 
47     [[nodiscard]] uint32_t GetResponseCode() const;
48 
49     [[nodiscard]] const std::map<std::string, std::string> &GetHeader() const;
50 
51     [[nodiscard]] const std::string &GetCookies() const;
52 
53     [[nodiscard]] const std::string &GetRawHeader() const;
54 
55     void SetResponseTime(const std::string &time);
56 
57     [[nodiscard]] const std::string &GetResponseTime() const;
58 
59     void SetRequestTime(const std::string &time);
60 
61     [[nodiscard]] const std::string &GetRequestTime() const;
62 
63     void SetWarning(const std::string &val);
64 
65 private:
66     std::string result_;
67 
68     std::string rawHeader_;
69 
70     uint32_t responseCode_;
71 
72     std::map<std::string, std::string> header_;
73 
74     std::string cookies_;
75 
76     std::string responseTime_;
77 
78     std::string requestTime_;
79 };
80 } // namespace OHOS::NetStack
81 
82 #endif /* COMMUNICATIONNETSTACK_HTTP_RESPONSE_H */
83