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