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