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 ARK_WEB_URL_RESOURCE_RESPONSE_WRAPPER_H_ 17 #define ARK_WEB_URL_RESOURCE_RESPONSE_WRAPPER_H_ 18 #pragma once 19 20 #include "include/nweb_url_resource_response.h" 21 #include "ohos_nweb/include/ark_web_url_resource_response.h" 22 23 namespace OHOS::ArkWeb { 24 25 using ArkWebResponseDataType = OHOS::NWeb::NWebResponseDataType; 26 27 class ArkWebUrlResourceResponseWrapper : public OHOS::NWeb::NWebUrlResourceResponse { 28 public: 29 ArkWebUrlResourceResponseWrapper(ArkWebRefPtr<ArkWebUrlResourceResponse> ark_web_url_resource_response); 30 ~ArkWebUrlResourceResponseWrapper() = default; 31 32 /** 33 * @brief get input stream 34 * 35 * @return inputstream string 36 */ 37 std::string ResponseData() override; 38 39 /** 40 * @brief set input stream 41 * 42 * @param input_stream set inputstream for example: fread(buf, 1, sizeof(buf), 43 * file) 44 */ 45 void PutResponseData(const std::string& input_stream) override; 46 47 /** 48 * @brief Get ReasonPhrase 49 * 50 * @return errorcode reason 51 */ 52 std::string ResponseStatus() override; 53 54 /** 55 * @brief Get ResponseHeaders 56 * 57 * @return response headers 58 */ 59 std::map<std::string, std::string> ResponseHeaders() override; 60 61 /** 62 * @brief Set ResponseHeaders 63 * 64 * @param response_headers response header 65 */ 66 void PutResponseHeaders(const std::map<std::string, std::string>& response_headers) override; 67 68 ArkWebResponseDataType ResponseDataType() override; 69 70 /** 71 * @brief Get mimetype 72 * 73 * @return mimetype The resource response's MIME type 74 */ 75 std::string ResponseMimeType() override; 76 77 /** 78 * @brief Construct a resource response with the given parameters. 79 * 80 * @param mime_type mime_type{ "text/html" } 81 */ 82 void PutResponseMimeType(const std::string& mime_type) override; 83 84 /** 85 * @brief get encoding 86 * 87 * @return encoding the resource response's encoding 88 */ 89 std::string ResponseEncoding() override; 90 91 /** 92 * @brief Construct a resource response with the given parameters. 93 * 94 * @param encoding encoding { "utf-8" } 95 */ 96 void PutResponseEncoding(const std::string& encoding) override; 97 98 bool ResponseDataStatus() override; 99 100 void PutResponseDataStatus(bool is_data_ready) override; 101 102 /** 103 * @brief Get status code 104 * 105 * @return status code 106 */ 107 int ResponseStatusCode() override; 108 109 std::string ResponseResourceUrl() override; 110 111 void PutResponseResourceUrl(const std::string& url) override; 112 113 int ResponseFileHandle() override; 114 115 void PutResponseFileHandle(int fd) override; 116 117 bool ResponseIsFileHandle() override; 118 119 void PutResponseStateAndStatuscode(int status_code, const std::string& reason_phrase) override; 120 121 void PutResponseReadyCallback(std::shared_ptr<OHOS::NWeb::NWebResourceReadyCallback> callback) override; 122 123 void PutResponseDataBuffer(char* buffer, size_t bufferSize) override; 124 125 char* GetResponseDataBuffer() override; 126 127 size_t GetResponseDataBufferSize() override; 128 129 private: 130 ArkWebRefPtr<ArkWebUrlResourceResponse> ark_web_url_resource_response_; 131 }; 132 133 } // namespace OHOS::ArkWeb 134 135 #endif // ARK_WEB_URL_RESOURCE_RESPONSE_WRAPPER_H_ 136