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