• 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 #include "napi/native_api.h"
23 
24 namespace OHOS::NetStack {
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 SetResponseCode(uint32_t responseCode);
34 
35     void ParseHeaders();
36 
37     void AppendCookies(const void *data, size_t length);
38 
39     [[nodiscard]] const std::string &GetResult() const;
40 
41     [[nodiscard]] uint32_t GetResponseCode() const;
42 
43     [[nodiscard]] const std::map<std::string, std::string> &GetHeader() const;
44 
45     [[nodiscard]] const std::string &GetCookies() const;
46 
47 private:
48     std::string result_;
49 
50     std::string rawHeader_;
51 
52     uint32_t responseCode_;
53 
54     std::map<std::string, std::string> header_;
55 
56     std::string cookies_;
57 };
58 } // namespace OHOS::NetStack
59 
60 #endif /* COMMUNICATIONNETSTACK_HTTP_RESPONSE_H */
61