1 /* 2 * Copyright (c) 2021 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 FOUNDATION_ACE_ADAPTER_PREVIEW_RESPONSEDATA_H 17 #define FOUNDATION_ACE_ADAPTER_PREVIEW_RESPONSEDATA_H 18 19 #include <unordered_map> 20 #include <string> 21 22 #include "base/json/json_util.h" 23 24 namespace OHOS::Ace { 25 26 namespace { 27 // error code 28 constexpr int32_t ACTION_SUCCESS = 0; 29 constexpr int32_t ACTION_FAIL = 1; 30 constexpr int32_t COMMON_ERROR_CODE = 200; 31 // httpcode 32 constexpr int32_t HTTP_OK = 200; 33 } // namespace 34 35 class ResponseData { 36 public: GetCode()37 int32_t GetCode() const 38 { 39 return code_; 40 } 41 SetCode(const int32_t code)42 void SetCode(const int32_t code) 43 { 44 code_ = code; 45 } 46 GetData()47 std::string GetData() const 48 { 49 return data_; 50 } 51 SetData(const std::string data)52 void SetData(const std::string data) 53 { 54 data_ = data; 55 } 56 GetHeaders()57 std::unordered_map<std::string, std::string> GetHeaders() const 58 { 59 return headers_; 60 } 61 62 void SetHeaders(std::string headersStr); 63 std::unique_ptr<JsonValue> GetResultString() const; 64 int GetActionCode() const; 65 private: 66 int32_t code_ = COMMON_ERROR_CODE; 67 std::string data_; 68 std::unordered_map<std::string, std::string> headers_; 69 70 std::unique_ptr<JsonValue> GetStringValue() const; 71 }; 72 } // namespace OHOS::Ace 73 74 #endif // #ifndef FOUNDATION_ACE_ADAPTER_PREVIEW_RESPONSEDATA_H 75