1 /* 2 * Copyright (c) 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_FETCH_RESPONSE_H 17 #define COMMUNICATIONNETSTACK_FETCH_RESPONSE_H 18 19 #include <map> 20 #include <string> 21 22 #include "napi/native_api.h" 23 24 namespace OHOS::NetStack::Fetch { 25 class FetchResponse final { 26 public: 27 FetchResponse(); 28 29 void AppendData(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 [[nodiscard]] const std::string &GetData() const; 38 39 [[nodiscard]] uint32_t GetResponseCode() const; 40 41 [[nodiscard]] const std::map<std::string, std::string> &GetHeader() const; 42 43 private: 44 std::string data_; 45 46 std::string rawHeader_; 47 48 uint32_t responseCode_; 49 50 std::map<std::string, std::string> header_; 51 }; 52 } // namespace OHOS::NetStack::Fetch 53 54 #endif /* COMMUNICATIONNETSTACK_FETCH_RESPONSE_H */ 55