1e41f4b71Sopenharmony_ci# Web Subsystem Changelog 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciCompared with earlier versions, OpenHarmony 4.0.7.3 has the following API changes in its web subsystem: 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci## cl.web.1 New Input Parameter Type of the setResponseData API 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciAdded the input parameter type **Resource** for the **setResponseData** API. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci**Change Impact** 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciIn the scenario where a HAP file is not decompressed, the file path in the HAP does not exist. Under this scenario, to access resources in the HAP file, you must use the input parameter **data:Resource** instead of **data:number**. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci**Key API/Component Changes** 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci- Involved APIs: 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci setResponseData 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci- Before change: 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci ``` 22e41f4b71Sopenharmony_ci setResponseData(data: string | number) 23e41f4b71Sopenharmony_ci ``` 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci- After change: 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci ``` 28e41f4b71Sopenharmony_ci setResponseData(data: string | number | Resource) 29e41f4b71Sopenharmony_ci ``` 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**Adaptation Guide** 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ciWhen a HAP file is decompressed, open the hold the FD of the target resource file, and then transfer the resource response data to the kernel through **setResponseData(data:number)**. 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci``` 36e41f4b71Sopenharmony_ci// xxx.ets 37e41f4b71Sopenharmony_ciimport web_webview from '@ohos.web.webview' 38e41f4b71Sopenharmony_ciimport fileio from '@ohos.fileio'; 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci@Entry 41e41f4b71Sopenharmony_ci@Component 42e41f4b71Sopenharmony_cistruct WebComponent { 43e41f4b71Sopenharmony_ci controller: web_webview.WebviewController = new web_webview.WebviewController() 44e41f4b71Sopenharmony_ci responseweb: WebResourceResponse = new WebResourceResponse() 45e41f4b71Sopenharmony_ci heads: Header[] = new Array() 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci build() { 48e41f4b71Sopenharmony_ci Column() { 49e41f4b71Sopenharmony_ci Web({ src: 'www.example.com', controller: this.controller }) 50e41f4b71Sopenharmony_ci .onInterceptRequest((event) => { 51e41f4b71Sopenharmony_ci console.log('url:' + event.request.getRequestUrl()) 52e41f4b71Sopenharmony_ci var head1:Header = { 53e41f4b71Sopenharmony_ci headerKey:"Connection", 54e41f4b71Sopenharmony_ci headerValue:"keep-alive" 55e41f4b71Sopenharmony_ci } 56e41f4b71Sopenharmony_ci var head2:Header = { 57e41f4b71Sopenharmony_ci headerKey:"Cache-Control", 58e41f4b71Sopenharmony_ci headerValue:"no-cache" 59e41f4b71Sopenharmony_ci } 60e41f4b71Sopenharmony_ci var length = this.heads.push(head1) 61e41f4b71Sopenharmony_ci length = this.heads.push(head2) 62e41f4b71Sopenharmony_ci this.responseweb.setResponseHeader(this.heads) 63e41f4b71Sopenharmony_ci this.responseweb.setResponseEncoding('utf-8') 64e41f4b71Sopenharmony_ci this.responseweb.setResponseMimeType('text/html') 65e41f4b71Sopenharmony_ci this.responseweb.setResponseCode(200) 66e41f4b71Sopenharmony_ci this.responseweb.setReasonMessage('OK') 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci //// fd scheme --start 69e41f4b71Sopenharmony_ci // '/xxx/.../test.html' is the local path of the file. 70e41f4b71Sopenharmony_ci // @ts-ignore 71e41f4b71Sopenharmony_ci let fd = fileio.openSync('/xxx/.../test.html', 0o102, 0o666) 72e41f4b71Sopenharmony_ci this.responseweb.setResponseData(fd) 73e41f4b71Sopenharmony_ci //// fd scheme --end 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci return this.responseweb 76e41f4b71Sopenharmony_ci }) 77e41f4b71Sopenharmony_ci } 78e41f4b71Sopenharmony_ci } 79e41f4b71Sopenharmony_ci} 80e41f4b71Sopenharmony_ci``` 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ciWhen a HAP file is decompressed, the file path in the HAP does not exist. In this case, transfer the resource response data to the kernel through **setResponseData(data:Resource)**. 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci``` 85e41f4b71Sopenharmony_ci// xxx.ets 86e41f4b71Sopenharmony_ciimport web_webview from '@ohos.web.webview' 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci@Entry 89e41f4b71Sopenharmony_ci@Component 90e41f4b71Sopenharmony_cistruct WebComponent { 91e41f4b71Sopenharmony_ci controller: web_webview.WebviewController = new web_webview.WebviewController() 92e41f4b71Sopenharmony_ci responseweb: WebResourceResponse = new WebResourceResponse() 93e41f4b71Sopenharmony_ci heads: Header[] = new Array() 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci build() { 96e41f4b71Sopenharmony_ci Column() { 97e41f4b71Sopenharmony_ci Web({ src: 'www.example.com', controller: this.controller }) 98e41f4b71Sopenharmony_ci .onInterceptRequest((event) => { 99e41f4b71Sopenharmony_ci console.log('url:' + event.request.getRequestUrl()) 100e41f4b71Sopenharmony_ci var head1:Header = { 101e41f4b71Sopenharmony_ci headerKey:"Connection", 102e41f4b71Sopenharmony_ci headerValue:"keep-alive" 103e41f4b71Sopenharmony_ci } 104e41f4b71Sopenharmony_ci var head2:Header = { 105e41f4b71Sopenharmony_ci headerKey:"Cache-Control", 106e41f4b71Sopenharmony_ci headerValue:"no-cache" 107e41f4b71Sopenharmony_ci } 108e41f4b71Sopenharmony_ci var length = this.heads.push(head1) 109e41f4b71Sopenharmony_ci length = this.heads.push(head2) 110e41f4b71Sopenharmony_ci this.responseweb.setResponseHeader(this.heads) 111e41f4b71Sopenharmony_ci this.responseweb.setResponseEncoding('utf-8') 112e41f4b71Sopenharmony_ci this.responseweb.setResponseMimeType('text/html') 113e41f4b71Sopenharmony_ci this.responseweb.setResponseCode(200) 114e41f4b71Sopenharmony_ci this.responseweb.setReasonMessage('OK') 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci //// Resource scheme --start 117e41f4b71Sopenharmony_ci // Specify the target file in the rawfile directory of the HAP file. 118e41f4b71Sopenharmony_ci this.responseweb.setResponseData($rawfile('test.html')) 119e41f4b71Sopenharmony_ci //// Resource scheme --end 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci return this.responseweb 122e41f4b71Sopenharmony_ci }) 123e41f4b71Sopenharmony_ci } 124e41f4b71Sopenharmony_ci } 125e41f4b71Sopenharmony_ci} 126e41f4b71Sopenharmony_ci``` 127