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