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 14e41f4b71Sopenharmony_ci**Key API/Component Changes** 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci- Involved APIs: 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci setResponseData 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci- Before change: 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci ```ts 23e41f4b71Sopenharmony_ci setResponseData(data: string | number) 24e41f4b71Sopenharmony_ci ``` 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci- After change: 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci ```ts 29e41f4b71Sopenharmony_ci setResponseData(data: string | number | Resource) 30e41f4b71Sopenharmony_ci ``` 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci**Adaptation Guide** 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_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)**. 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci```ts 37e41f4b71Sopenharmony_ci// xxx.ets 38e41f4b71Sopenharmony_ciimport web_webview from '@ohos.web.webview' 39e41f4b71Sopenharmony_ciimport fileio from '@ohos.fileio'; 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci@Entry 42e41f4b71Sopenharmony_ci@Component 43e41f4b71Sopenharmony_cistruct WebComponent { 44e41f4b71Sopenharmony_ci controller: web_webview.WebviewController = new web_webview.WebviewController() 45e41f4b71Sopenharmony_ci responseweb: WebResourceResponse = new WebResourceResponse() 46e41f4b71Sopenharmony_ci heads: Header[] = new Array() 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci build() { 49e41f4b71Sopenharmony_ci Column() { 50e41f4b71Sopenharmony_ci Web({ src: 'www.example.com', controller: this.controller }) 51e41f4b71Sopenharmony_ci .onInterceptRequest((event) => { 52e41f4b71Sopenharmony_ci console.log('url:' + event.request.getRequestUrl()) 53e41f4b71Sopenharmony_ci var head1:Header = { 54e41f4b71Sopenharmony_ci headerKey:"Connection", 55e41f4b71Sopenharmony_ci headerValue:"keep-alive" 56e41f4b71Sopenharmony_ci } 57e41f4b71Sopenharmony_ci var head2:Header = { 58e41f4b71Sopenharmony_ci headerKey:"Cache-Control", 59e41f4b71Sopenharmony_ci headerValue:"no-cache" 60e41f4b71Sopenharmony_ci } 61e41f4b71Sopenharmony_ci var length = this.heads.push(head1) 62e41f4b71Sopenharmony_ci length = this.heads.push(head2) 63e41f4b71Sopenharmony_ci this.responseweb.setResponseHeader(this.heads) 64e41f4b71Sopenharmony_ci this.responseweb.setResponseEncoding('utf-8') 65e41f4b71Sopenharmony_ci this.responseweb.setResponseMimeType('text/html') 66e41f4b71Sopenharmony_ci this.responseweb.setResponseCode(200) 67e41f4b71Sopenharmony_ci this.responseweb.setReasonMessage('OK') 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci //// fd scheme --start 70e41f4b71Sopenharmony_ci // '/xxx/.../test.html' is the local path of the file. 71e41f4b71Sopenharmony_ci // @ts-ignore 72e41f4b71Sopenharmony_ci let fd = fileio.openSync('/xxx/.../test.html', 0o102, 0o666) 73e41f4b71Sopenharmony_ci this.responseweb.setResponseData(fd) 74e41f4b71Sopenharmony_ci //// fd scheme --end 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci return this.responseweb 77e41f4b71Sopenharmony_ci }) 78e41f4b71Sopenharmony_ci } 79e41f4b71Sopenharmony_ci } 80e41f4b71Sopenharmony_ci} 81e41f4b71Sopenharmony_ci``` 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_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)**. 84e41f4b71Sopenharmony_ci```ts 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