Service request response processing method and device, equipment, storage medium and product

By encoding and formatting business response information through a proxy server, the security risks under the browser's same-origin policy restriction are resolved, XSS attacks are protected, and the security of browser pages is improved.

CN121603239APending Publication Date: 2026-03-03TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411178722.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-26
Publication Date
2026-03-03

AI Technical Summary

Technical Problem

Due to the browser's same-origin policy, the runtime environment and the mini-program's business interface are not from the same origin, which causes the browser to disallow the scripts in the runtime environment from sending business requests, posing a security risk. Hackers can exploit this feature to carry out XSS attacks.

Method used

By using a proxy server to encode and convert the business response information to generate the target response information, malicious scripts are prevented from being executed immediately in the browser, thus enhancing security.

Benefits of technology

It effectively prevents browser pages from being illegally attacked, improves the security of same-origin pages in the operating environment, prevents malicious script injection, and enhances security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121603239A_ABST
    Figure CN121603239A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a response processing method and device for a service request, equipment, a storage medium and a product, and the method comprises the steps: receiving target response information returned by a proxy server for the service request, and enabling a target response header of the target response information to comprise a coding response header generated by the server through the coding of an obtained service response header, the target response body of the target response information is obtained by converting the obtained service response body into a specific transmission format by the server. And decoding the coding response header, and after generating service response information based on the target response body and the response header obtained by decoding, performing response processing on the service request based on the service response information. According to the technical scheme provided by the embodiment of the invention, the business response body is converted into the specific transmission format instead of a file which can be immediately executed by the browser, and the browser cannot immediately execute the file which possibly comprises the malicious script after receiving the target response information, so that the webpage loaded by the browser is prevented from being illegally attacked.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, specifically to a method, apparatus, device, storage medium, and product for processing responses to business requests. Background Technology

[0002] With the rapid development of internet technology, mini-programs, as a lightweight application format, have been widely used in various fields. The emergence of runtime environments that support mini-programs running in browsers has further expanded their application scenarios. However, due to the browser's same-origin policy, the runtime environment and the mini-program's business interface are not from the same origin, causing the browser to disallow scripts in the runtime environment from sending business requests to the business interface. To solve this problem, a server needs to be introduced as a proxy to forward the mini-program's business requests, thus bypassing the same-origin policy restriction.

[0003] In this technical architecture, the runtime environment and the browser's pages share the same origin, allowing scripts in the runtime environment to access and manipulate the browser's pages. This same-origin characteristic poses a security risk. Hackers can exploit this feature to intercept and tamper with business requests, replacing business interfaces with illegitimate ones. Subsequently, through a server proxy, malicious scripts that can be immediately executed by the browser can be sent as a response. Once the response reaches the browser, it will be executed, launching a cross-site scripting (XSS) attack against the same-origin page in the runtime environment. This injects malicious scripts (code) into a trusted website, causing the browser to load and execute the maliciously created web page program, posing a serious security risk. Summary of the Invention

[0004] This application provides a method, apparatus, device, storage medium, and product for handling business requests, which can effectively prevent pages in a browser from being illegally attacked.

[0005] In a first aspect, embodiments of this application provide a method for processing a response to a business request, comprising:

[0006] The system receives target response information returned by the proxy server in response to a business request. The target response information includes a target response header and a target response body. The target response header includes an encoded response header generated by the proxy server encoding the obtained business response header. The target response body is obtained by the proxy server converting the obtained business response body into a specific transmission format.

[0007] The encoded response header is decoded, and service response information is generated based on the target response body and the decoded response header.

[0008] The service request is processed based on the service response information.

[0009] Secondly, embodiments of this application provide a method for processing responses to business requests, including:

[0010] Obtain the business response headers and body associated with the business request from the business server;

[0011] The business response header is encoded, and the target response header is constructed based on the encoded response header obtained from the encoding process;

[0012] The service response body is converted into a specific transmission format to obtain the target response body, and target response information is generated based on the target response header and the target response body;

[0013] The target response information is sent to the client so that the client can decode the encoded response header and generate business response information for the business request based on the target response body and the decoded response header.

[0014] Thirdly, embodiments of this application provide a service request response processing apparatus, comprising:

[0015] The receiving unit is used to receive target response information returned by the proxy server in response to the business request. The target response information includes a target response header and a target response body. The target response header includes an encoded response header generated by the proxy server encoding the obtained business response header. The target response body is obtained by the proxy server converting the obtained business response body into a specific transmission format.

[0016] The processing unit is configured to decode the encoded response header, generate service response information based on the target response body and the decoded response header, and process the service request based on the service response information.

[0017] In one possible implementation, the device further includes:

[0018] The generation unit is used to generate a business request corresponding to the input operation in response to the received input operation for the specified application page.

[0019] The sending unit is configured to send the service request to the proxy server, so that the proxy server can obtain the service response header and the service response body from the service server indicated by the service request.

[0020] In one possible implementation, the designated application includes a hosting program that runs in a runtime environment provided by the host program, and the host program also runs service components; the sending unit is used to send the service request to the proxy server, specifically for:

[0021] If a business request associated with the page of the hosting program is detected, the address of the business server contained in the business request is modified to a proxy address that is of the same origin as the address of the service component through the runtime environment;

[0022] If a service request with an address that originates from the same source as the address of the service component is detected, the service component will intercept the service request and forward the intercepted service request to the proxy server.

[0023] In one possible implementation, the device further includes:

[0024] The acquisition unit is used to acquire the script file corresponding to the target page in response to the loading request of the target page. The script file includes the registration script of the service component, and the registration script indicates the address and control scope of the service component.

[0025] The execution unit is used to run the script file to load the target page and obtain the installation file of the service component based on the address of the service component;

[0026] The deployment unit is used to deploy the service component based on the installation file and trigger the service component to monitor and process business requests associated with the pages within the control scope.

[0027] In one possible implementation, the target page includes controls corresponding to at least one candidate hosting program. The acquisition unit is further configured to, in response to a trigger operation on the control corresponding to the hosting program in the target page, acquire the resource file of the hosting program from a server associated with the runtime environment, and load the page of the hosting program based on the resource file.

[0028] In one possible implementation, the acquiring unit is further configured to acquire the script file again in response to a reload request for the target page;

[0029] The running unit is also used to run the script file that has been obtained again, so as to reload the target page and obtain the update installation file of the service component based on the address of the service component;

[0030] The processing unit is further configured to update the service component based on the updated installation file if the updated installation file is updated compared to the installation file.

[0031] In one possible implementation, the processing unit is configured to update the service component based on the update installation file, specifically for:

[0032] The update service component is obtained by performing an installation process based on the update installation file.

[0033] If it is detected that a page within the control scope has been closed, the update service component is triggered to monitor and process the business requests associated with the page within the control scope.

[0034] In one possible implementation, the running unit is further configured to stop running the service component if no business request associated with the page within the control range is detected within a preset time period.

[0035] After the service component is stopped, if a new business request with the same address as the service component is detected on a page within the control scope, the service component is restarted and the new business request is intercepted and processed through the service component.

[0036] In one possible implementation, the target response header also includes parsing information used to indicate a predefined response header;

[0037] The processing unit is used to decode the encoded response header, specifically for:

[0038] Access the encoded response header stored in the predefined response header indicated by the parsing information;

[0039] The encoded response header is decoded based on a preset decoding method.

[0040] In one possible implementation, the processing unit is configured to respond to the service request based on the service response information, specifically for:

[0041] If the business logic associated with the business request determines that the business request and the business response information do not match, then error processing is performed based on the business response information.

[0042] Fourthly, embodiments of this application provide a service request response processing apparatus, comprising:

[0043] The acquisition unit is used to acquire the business response headers and business response bodies associated with the business request, which are returned by the business server.

[0044] The processing unit is used to encode the service response header and construct the target response header based on the encoded response header obtained from the encoding process.

[0045] A conversion unit is used to convert the service response body into a specific transmission format to obtain a target response body, and to generate target response information based on the target response header and the target response body;

[0046] The sending unit is used to send the target response information to the client, so that the client can decode the encoded response header and generate service response information for the service request based on the target response body and the decoded response header.

[0047] In one possible implementation, the acquisition unit is used to acquire the business response header and business response body associated with the business request returned by the business server, specifically for:

[0048] Send a proxy service request generated based on the service request to the service server indicated by the service request, wherein the service request is generated and sent by the client in response to an input operation on a specified application page;

[0049] Receive the service response header and the service response body returned by the service server.

[0050] In one possible implementation, the processing unit is configured to construct a target response header based on the encoded response header obtained from the encoding process, comprising:

[0051] The encoded response header is stored in a predefined response header, and parsing information is generated to instruct the client to access the predefined response header;

[0052] The target response header is constructed based on the predefined response header and the parsed information.

[0053] In one possible implementation, the processing unit is configured to construct a target response header based on the encoded response header obtained from the encoding process, comprising:

[0054] Based on the predefined response header and the parsed information, the target response header is constructed, including:

[0055] Generate content type information to indicate the specific transmission format;

[0056] The target response header is constructed based on the content type information, the predefined response header, and the parsing information.

[0057] In one possible implementation, the processing unit is configured to construct a target response header based on the encoded response header obtained from the encoding process, comprising:

[0058] Based on the content type information, the predefined response header, and the parsing information, the target response header is constructed, including:

[0059] The specific field in the business response header is checked. If the business response header is found to include the specific field, response attribute information is generated based on the specific field and its corresponding value.

[0060] The target response header is constructed based on the response attribute information, the content type information, the predefined response header, and the parsing information.

[0061] Fifthly, embodiments of this application provide an electronic device, which includes one or more processors; and a memory for storing one or more computer programs, which, when executed by the one or more processors, cause the electronic device to implement the service request response processing method described in the first aspect or the second aspect above.

[0062] Sixthly, embodiments of this application provide a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the response processing method for the business request described in the first or second aspect.

[0063] In a seventh aspect, embodiments of this application provide a computer program product, which includes a computer program or computer instructions. When the computer program or computer instructions are executed by a processor, they implement a response processing method for a business request as described in the first aspect or the second aspect.

[0064] In some embodiments of this application, the proxy server encodes the obtained business response headers and converts the business response body into a specific transmission format, sending the encoded response headers and the converted response body as target response information to the client. The client can decode the encoded response headers and generate business response information based on the target response body and the decoded response headers. The client can then respond to the business requests of the mini-program running in its runtime environment based on the business response information. Therefore, when the target response information is returned to the browser in the client, since the target response body is not a file that the browser can immediately execute, but rather data in a specific transmission format, the browser will not immediately execute the file, which may contain malicious scripts, after receiving the target response information. This helps prevent hackers from exploiting the same-origin policy to inject malicious scripts into the business code (iframe) of the mini-program that is from the same origin as the runtime environment, thereby protecting the same-origin pages of the runtime environment from malicious script attacks and improving the security of the same-origin pages of the runtime environment. Furthermore, the proxy server can encode the obtained business response headers to prevent malicious content from being directly transmitted to the browser when the business response headers contain malicious or illegal text, thereby further enhancing security. Attached Figure Description

[0065] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0066] Figure 1 This is a schematic diagram of an architecture for proxy service requests;

[0067] Figure 2 This is a schematic diagram of the architecture of a business request response processing system provided in an embodiment of this application;

[0068] Figure 3 This application provides a flowchart illustrating a method for handling the response of a business request.

[0069] Figure 4 This is a schematic diagram of a user interface for a hosted program running on a host program, provided in an embodiment of this application.

[0070] Figure 5 This is a schematic diagram of a user interface for a target page provided in an embodiment of this application;

[0071] Figure 6 This is a schematic diagram of the architecture of a proxy service request provided in an embodiment of this application;

[0072] Figure 7 This is a schematic diagram of the structure of a service request response processing device provided in an embodiment of this application;

[0073] Figure 8 This is a schematic diagram of the structure of another service request response processing device provided in an embodiment of this application;

[0074] Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0075] It should be noted in advance that, in order to enable those skilled in the art to better understand the technical solutions proposed in the embodiments of this application, the embodiments of this application will be described clearly and completely in conjunction with one or more accompanying drawings. Furthermore, the various drawings shown in the embodiments of this application are merely illustrative examples; for example, the execution order of each step in the drawings can be adaptively adjusted according to the actual application scenario. In addition, in the embodiments of this application, the block diagrams shown in the various drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, or in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.

[0076] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.

[0077] It should be noted that "multiple" in this article refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.

[0078] Currently, web browsers can run runtime environments that support mini-programs. A mini-program can be understood as a hosted program running within a runtime environment provided by the host program (browser), which can be the browser runtime. Browsers have a same-origin policy, which means that if two web pages loaded by the browser have the same protocol, domain name (hostname), and port number, then a script on one web page can access data on the other. Due to this same-origin policy restriction, the runtime environment and the mini-program's business interface are usually not from the same origin, causing the browser to disallow scripts in the runtime environment from sending business requests to the business interface to obtain data. Therefore, a proxy server can be introduced to proxy the business requests associated with the mini-program. After the business request is sent from the runtime environment, it passes through the proxy server, where it is proxied. The proxy server can then return the business response obtained from the business interface to the runtime environment, thereby bypassing the browser's same-origin policy restriction.

[0079] Please refer to the following: Figure 1 , Figure 1 This is a schematic diagram of an architecture for proxying business requests, such as... Figure 1 As shown, a browser can interact with a proxy server. The browser can send a business request to the proxy server, and after receiving the business request, the proxy server can proxy the request, such as... Figure 1 The proxy server uses the `fetch` function to act as a proxy. Through `fetch`, the proxy server can forward business requests to the indicated business interface (another server), and then return the corresponding business response to the original requester, i.e., the browser. The browser can run a runtime environment that supports running mini-programs, such as Browser-Runtime. This runtime environment provides a specific component. When the user specifies the mini-program they want to run in the browser, such as specifying a mini-program identifier (appid), and passes this identifier to the component, the component creates multiple iframes with the same origin as the current page in the browser. Simultaneously, the component requests the business code and basic library of the mini-program indicated by the mini-program identifier from the server associated with the runtime environment, and injects the business code and basic library into the corresponding iframes, thus enabling the browser to run the mini-program and load its user interface.

[0080] In this context, an iframe, also known as a page, refers to an inline frame element in Hyper Text Markup Language (HTML), allowing another HTML page to be embedded within the current page. In a browser runtime environment that supports mini-programs, an iframe can be understood as creating a frame (page) with the same origin as the current page to support different functions and components of the mini-program. It's important to note that an iframe can be divided into basic capabilities (Native), a view (WebView), and logic code (AppService). The basic capabilities (Native), also known as the Native layer, are used to inject the code for the mini-program's basic capabilities. The view (WebView), also known as the WebView layer, is used to load and run the content of the mini-program's pages. The WebView can interact with the basic capabilities (Native) to provide a visual interface through which users can interact with the mini-program. The mini-program's view layer code can be rendered into this iframe for display to the user. The logic code (AppService), also known as the AppService layer, is used to load and run the mini-program's business logic. The mini-program's logic layer code (such as JavaScript) is injected into this iframe for execution. The logic code (AppService) can interact with the basic capabilities (Native) to run the mini-program's business logic in the browser, process user input, and interact with the server, etc.

[0081] Understanding this, the runtime environment can be considered an iframe. This iframe can be referred to as the current page or the current browser page. The runtime environment can provide multiple components, each of which can create multiple iframes for a corresponding mini-program. The frames (pages) of the mini-programs created by these components can be called child pages (child iframes) of the runtime environment's iframes. Therefore, the basic capabilities (Native), views (WebView), and logic code (AppService) within the runtime environment are all of the same origin as the runtime environment itself and the pages running it. Browsers allow business logic code running at the AppService layer to access and manipulate the runtime environment's pages (iframes) and pages (iframes) of the same origin. It's important to note that while the runtime environment's pages are also called browser pages, they are merely JavaScript scripts loaded within the runtime environment (i.e., containing running code) and may not necessarily contain page content.

[0082] In this architecture, when a user interacts with the visual interface of a mini-program loaded by the browser, the business code in the AppService layer can generate a business request and send it to the proxy server through the runtime environment. After the browser receives the business response from the proxy server, this response is returned to the business code in the AppService layer, which can then execute the corresponding response processing based on business logic. In this scenario, a hacker might intercept the business request sent from the browser and replace the requested business interface with an illegal interface. The proxy server can then obtain a response from the server indicated by this illegal interface. This response may include malicious script files that the browser can execute immediately, such as HTML files. The malicious script could be used within the HTML file... <script>标签注入的恶意JavaScript代码,在该HTML文件到达浏览器,便会被浏览器立即解析(执行),这是浏览器所具有的能力,用户无法对其进行控制,即用户无法控制浏览器不执行该HTML文件,从而导致AppService层(iframe)的业务代码被注入恶意脚本,使得运行环境的同源页面(iframe)会遭受XSS攻击,例如进行敏感信息(如Cookie)的获取、植入恶意广告脚本等。

[0083] 基于此,本申请实施例提供了一种业务请求的响应处理方案,通过代理服务器将获取到的业务响应体转换为特定传输格式,如转换为二进制流数据格式(buffer)后,再发送至浏览器。浏览器在接收到代理服务器发送的响应后,由于其不是一个可立即执行的文件,如HTML文件,而是流式数据,浏览器不会在接收到响应后立即执行该包含恶意脚本的文件,在一定程度上能避免运行环境的同源页面受到XSS攻击,提高运行环境的同源页面的安全性,实现一种用户无感知的,业务请求代理的安全策略。并且,代理服务器可以对获取到的业务响应头进行编码,并将基于编码生成的编码响应头和格式转换后的响应头作为响应发送至浏览器,以在业务响应头中包含恶意、非法文字(字符)时,避免代理服务器直接向浏览器发送恶意、非法的文字,可以防止潜在的攻击或者恶意内容直接被传递至浏览器,从而进一步增强安全性。

[0084] 基于上述描述,请参阅图2,图2是本申请实施例提供的一种业务请求的响应处理系统的架构示意图,如图2所示,该业务请求的响应处理系统包括用户设备201、代理服务器202、业务服务器203以及与服务组件对应的服务器204。其中,代理服务器202与用户设备201和业务服务器203可以通过有线或无线的方式进行直接或者间接的连接,用户设备201可以与服务组件关联的服务器204通过有线或无线的方式进行直接或者间接的连接。需要说明的是,图2所示的设备数量和形态用于举例,并不构成对本申请实施例的限定。在一些实施例中,与服务组件关联的服务器可以与用户设备201为同一电子设备,即该服务组件的安装文件可以是静态资源文件。

[0085] 其中,用户设备201为电子设备,具体可以为终端设备,终端设备可以包括但不限于:智能手机(如Android手机、IOS手机等)、平板电脑、便携式个人计算机、移动互联网设备(Mobile Internet Devices,MID)、智能语音交互设备、智能家电、车载终端、飞行器、可穿戴设备等,本申请实施例对此不做限定;代理服务器202、业务服务器203和与服务组件对应的服务器204可以是独立的物理服务器,也可以是多个物理服务器构成的服务器集群或者分布式系统,还可以是提供云服务、云数据库、云计算、云函数、云存储、网络服务、云通信、中间件服务、域名服务、安全服务、内容分发网络(Content Delivery Network,CDN)、以及大数据和人工智能平台等基础云计算服务的云服务器,本申请实施例对此不做限定。

[0086] 其中,用户设备201可以为用户所使用的电子设备,该用户设备201可以运行浏览器程序,在浏览器程序中可以运行支持小程序运行在浏览器运行的运行环境,如Browser-runtime,以运行用户指定的小程序。浏览器还可以运行有服务组件,例如Service Worker脚本,其能够在浏览器的后台运行,可以拦截并处理网络请求。在本申请实施例中,该服务组件可以拦截从运行环境基于小程序发出的业务请求,并转发至代理服务器202,也可以用于在接收到代理服务器202返回的目标响应信息后,基于该目标响应信息生成业务响应信息,并将业务响应信息返回至运行环境中的小程序的业务代码,以使该小程序的业务代码可以基于该业务响应信息执行对应的响应处理。

[0087] 其中,代理服务器202可以是运行有中间层服务的软件的服务器,代理服务器是指在前端和后端之间起中介作用的服务器,例如Node.js服务器(Node.jsserver),该服务器也可以称为中间层服务器、node服务器、前端中间层(node)等,是使用Node.js技术栈构建的服务器,能在服务器端提供基于Chrome V8引擎的JavaScript语言编写的代码的运行环境。该代理服务器202可以运行有中间层服务的软件,如node.js软件,可以用于在前端(如用户设备201运行的浏览器)和后端(如业务服务器203)之间起中介作用。在本申请实施例中,代理服务器202可以对用户设备201中发出的业务请求进行代理,并将业务请求对应的业务响应信息进行处理后返回至该用户设备201中的浏览器。

[0088] 其中,业务服务器203可以为运行有为小程序提供后台服务的软件的电子设备,该业务服务器203也可以称为后台服务器、后端服务器等。业务服务器203可以用于处理小程序的业务逻辑、处理数据、存储数据等任务。在本申请实施例中,业务服务器203可以接收代理服务器202发送的业务请求,并基于业务请求执行相应的业务逻辑的处理,以将小程序所请求的数据作为响应返回至代理服务器202。在一些实施例中,在黑客拦截了用户设备201发送至代理服务器202的业务请求后,对业务请求中的业务接口替换为黑客部署的非法接口,则该业务服务器203也可以为该非法接口对应的服务器,为可以用于植入恶意脚本的服务器。

[0089] 其中,服务组件对应的服务器204可以是用于注册服务组件的电子设备,该服务组件具有自己的生命周期管理机制,包括注册、安装、激活和终止等状态。该服务组件对应的服务器204中可以部署有服务组件的安装文件,浏览器可以在注册过程中获取该安装文件,并基于该安装文件部署该服务组件。

[0090] 本申请提供的响应信息的处理方法的大致流程如下:

[0091] 用户设备201接收代理服务器202针对业务请求返回的目标响应信息,该目标响应信息包括目标响应头和目标响应体。其中,目标响应头包括代理服务器202对获取到的业务响应头进行编码所生成的编码响应头,目标响应体是代理服务器202将获取到的业务响应体转换为特定传输格式得到的。在用户设备201接收代理服务器202针对业务请求返回的目标响应信息之前,用户设备201可以在浏览器中加载指定应用程序页面,并接收用户输入的针对指定应用程序页面的输入操作,生成该输入操作对应的业务请求。进而,用户设备201可以将该业务请求发送至代理服务器202,以使代理服务器202从业务请求指示的业务服务器203中获取该业务响应头和业务响应体。

[0092] 其中,在用户设备201将该业务请求发送至代理服务器202的过程中,用户设备201运行的浏览器中的服务组件可以拦截该业务请求,并将拦截到的业务请求转发至代理服务器202。在用户设备201接收代理服务器202针对业务请求返回的目标响应信息后,可以通过服务组件对目标响应头中的编码响应头进行解码处理,并基于目标响应体和解码处理得到的响应头生成业务响应信息,进而服务组件可以将该业务响应信息传递至该浏览器运行的运行环境,以使该运行环境基于该业务响应信息对业务请求进行响应处理。

[0093] 在一个实现方式中,上述业务请求、目标响应信息、编码响应头、业务响应信息等均可以保存在区块链中,可以防止这些信息被篡改。其中,区块链是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式,其本质上是一个去中心化的数据库,是一串使用密码学方法相关联产生的数据块,每一个数据块中包含了一批次网络交易的信息,用于验证其信息的有效性(防伪)和生成下一个区块。

[0094] 可以理解的是,本申请实施例描述的业务请求的响应处理系统是为了更加清楚的说明本申请实施例的技术方案,并不构成对于本申请实施例提供的技术方案的限定,本领域普通技术人员可知,随着系统架构的演变和新业务场景的出现,本申请实施例提供的技术方案对于类似的技术问题,同样适用。

[0095] 基于上述业务请求的响应处理系统,请参阅图3,图3是本申请实施例提供了一种业务请求的响应处理方法的流程示意图,该业务请求的响应处理方法可由客户端和代理服务器交互实现。其中,客户端可以是图2所示的用户设备201,具体可以指该用户设备201中运行的浏览器,代理服务器可以是图2所示的代理服务器202,该业务请求的响应处理方法可以包括以下步骤S301-S305,其中:

[0096] S301、代理服务器获取业务服务器反馈的与业务请求关联的业务响应头和业务响应体。

[0097] 在本申请实施例中,代理服务器可以为在前端和后端之间起中介作用的服务器,例如Node.js服务器(Node.js server),该代理服务器也可以称为中间层服务器、node服务器、前端中间层(node)等,是使用Node.js技术栈构建的服务器,能在服务器端提供运行JavaScript语言编写的代码的运行环境,可以用于处理权限验证、数据格式转换等任务,使得前后端交互更加灵活和安全。例如在如图1所示的架构中,为了绕过同源策略的限制,可以通过代理服务器对客户端发送的请求进行代理。业务服务器可以为网页提供后台服务的服务器,该业务服务器也可以称为后台服务器、后端服务器等。业务服务器可以用于处理网页的业务逻辑、处理数据、存储数据等任务。若在客户端中运行的浏览器可以加载指定应用程序的页面,则该业务服务器是为该指定应用程序提供后台服务的服务器。

[0098] 其中,业务请求是一个超文本传输协议(HyperText Transfer Protocol,HTTP)请求,用于向业务服务器请求特定的数据或执行特定的操作。业务响应头和业务响应体是响应信息的两部分,该响应信息是该业务服务器基于该业务请求所指示的特定的数据或者执行特定的操作后生成并返回至代理服务器的,是一个HTTP响应。业务响应头(ResponseHeader)可以用于提示关于该HTTP响应的附加信息,该业务响应头可以指示客户端如何正确处理业务响应体中的数据。示例性的,业务响应头中可以包括Content-Type字段、Content-Length字段和Set-Cookie字段等,Content-Type字段用于指示业务响应体的类型,用于告诉客户端实际返回内容的类型,Content-Length字段用于指示业务响应体的长度,以字节为单位,以使客户端了解响应体的大小,从而正确地接收和处理数据。如果服务器希望客户端存储一些信息,业务响应头中可以包括Set-Cookie字段所指示的一个或多个cookie。

[0099] 需要说明的是,上述业务响应头所包括的每个字段可以称为响应头字段,也可以称为响应头。其中,业务响应体(Response Body)是业务服务器实际返回的数据内容。它紧随业务响应头之后,是HTTP响应的主要部分。业务响应体的内容取决于业务请求的类型和目的,可能包含HTML文档、JSON数据、图片、视频等多种类型的数据。例如,业务请求为GET请求,该业务响应体通常包含请求的资源。再例如,业务请求为POST请求,若请求的目的是提交数据给业务服务器处理,则该业务响应体可能包含处理结果或状态信息。业务响应体中的数据是客户端真正需要的内容,它根据业务请求的不同而有所变化。

[0100] 在一种可能的实现方式中,代理服务器获取业务服务器反馈的与业务请求关联的业务响应头和业务响应体,可以是由客户端触发的。在本申请实施例中,客户端指运行在用户设备中安装的浏览器软件,在下文中存在以浏览器为主体和客户端为主体进行描述,其可以表示同一主体执行的操作或处理。具体地,客户端可以响应于接收到的针对指定应用程序页面的输入操作,生成输入操作对应的业务请求,进而客户端可以向代理服务器发送业务请求,以使代理服务器从业务请求指示的业务服务器中获取业务响应头和业务响应体,即代理服务器可以向业务请求指示的业务服务器发送基于业务请求生成的代理业务请求,并接收业务服务器返回的业务响应头和业务响应体。

[0101] 其中,指定应用程序页面是客户端运行的浏览器所加载指定应用程序的页面,输入操作为用户针对该指定应用程序页面输入的操作。指定应用程序可以为浏览器运行的应用程序,如网页应用等。例如,指定应用程序页面为客户端(浏览器)所加载出的页面,用户可以基于浏览器加载出的页面进行输入操作,如点击按钮控件、填写表单并提交等。进而,浏览器可以基于该指定应用程序的业务代码(如AppService层的iframe)中的业务逻辑和该输入操作,生成相应的请求信息,该请求信息包括请求方法,如Get、Post等,请求统一资源定位器(Uniform Resource Locator,URL),可以用于指示业务服务器,请求头,如关于请求的元信息,以及请求体,例如,如果请求方法指示是Post请求,则包括用户提交的数据,得到输入操作对应的业务请求。进而,客户端可以将该业务请求发送至代理服务器。

[0102] 可以理解的是,由于该业务请求是从客户端发送至代理服务器的,该业务请求中的URL可以用于指示代理服务器的地址,进而,代理服务器在接收到该业务请求后,可以根据其配置或者规则,对该业务请求进行处理或修改,将该用于指示代理服务器的地址修改为实际业务服务器的URL,从而完成对业务请求的处理。其中,代理业务请求可以是代理服务器基于对业务请求进行修改后生成的,如上述对业务请求中用于指示代理服务器的地址修改为用于指示业务服务器的地址。进而,代理服务器可以向业务请求所指示的业务服务器发送代理业务请求,以请求该业务请求中的请求方法所对应的数据或结果。进而,该代理服务器可以接收业务服务器返回的业务响应头和业务响应体。

[0103] 在一种可能的实现方式中,该指定应用程序包括寄宿程序,该寄宿程序运行在宿主程序所提供的运行环境中。其中,寄宿程序可以是指不能直接在宿主程序中运行的应用程序,在本申请实施例中具体可以是指小程序(miniprogram),小程序也称为快应用等,可以直接运行在特定的应用程序中,但不能运行在浏览器中,是一种无需下载安装即可使用的应用程序。宿主程序可以是指浏览器程序,该宿主程序所提供的运行环境是指支持小程序在浏览器运行的运行环境,例如上述Browser-Runtime,使得小程序可以运行在浏览器所提供的运行环境中。该宿主程序中还运行有服务组件,该服务组件可以是指ServiceWorker,即一个运行在宿主程序(浏览器)后台的独立线程,也可以理解为在宿主程序(浏览器)后台中运行的脚本。Service Worker有着独立的JavaScript运行环境,可以分担、协助前端页面完成需要在后台执行的任务,例如可以拦截受控页面的网络请求。

[0104] 请一并参阅图4,图4是本申请实施例提供的一种寄宿程序运行在宿主程序的用户界面示意图,如图4所示,该用户界面可以是运行在用户设备中的界面,本申请实施例以宿主程序为浏览器程序,寄宿程序为运行在特定应用程序中的小程序。图4以一个表单工具小程序为例进行绘制和讲解,该表单工具小程序可以运行在浏览器提供的运行环境中,也就是说,浏览器可以加载该表单工具小程序的用户界面,如图4所示的包括多个用于创建表单的控件,如"创建表单”、"发起抽签”,以及"常用表单”中的"签到表”、"通讯录收集”等。进而,用户可以针对该用户界面的控件输入操作,以触发该小程序的业务代码生成与该输入操作对应的业务请求。

[0105] 具体地,在客户端向代理服务器发送业务请求的过程中,客户端可以检测是否存在与寄宿程序的页面关联的业务请求,若检测到与寄宿程序的页面关联的业务请求,则通过运行环境将业务请求中包含的业务服务器的地址修改为与服务组件的地址同源的代理地址。进而,客户端可以通过服务组件对与寄宿程序的页面关联的业务请求进行监测处理,若该服务组件监测到所包含的地址与服务组件的地址同源的业务请求,则客户端可以通过服务组件对业务请求进行拦截处理,并将拦截到的业务请求转发至代理服务器。需要说明的是,由于需要代理服务器对业务请求进行代理,并且后续还需要服务组件针对代理服务器返回的响应信息进行处理,因此在客户端向代理服务器发送业务请求的过程中,可以通过服务组件对业务请求进行拦截处理,并将拦截到的业务请求发送至代理服务器。

[0106] 在一些实施例中,客户端可以通过服务组件拦截业务请求后,对该业务请求进行加密处理,这种方式可以增加黑客拦截该业务请求后,篡改该业务请求中的业务接口的难度,在一定程度上也能防止网页受到黑客的攻击,从而有利于提高安全性。

[0107] 由于服务组件仅能拦截其控制范围内的业务请求,该控制范围可以是在该服务组件注册的过程中指定的,该控制范围可以是指服务组件的作用域,其作用域可以包括该寄宿程序的页面中所包含的地址与服务组件的地址同源的业务请求,则服务组件可以拦截该寄宿程序的页面中所包含的地址与服务组件的地址同源的业务请求。例如,服务组件的地址为https: / / a.com / sw.js,则服务组件不能拦包含的地址为https: / / b.com的业务请求,因为https: / / b.com与服务组件的地址不同源,服务组件可以拦截包含的地址与https: / / a.com同源的业务请求,如拦截包含的地址为https: / / a.com / xxx的业务请求。由此,在生成输入操作对应的业务请求后,可以通过运行环境检测与寄宿程序的页面关联的业务请求,并通过运行环境将其包括的包含的业务服务器的地址修改为与服务组件的地址同源的代理地址,以通过该服务组件对修改地址后的业务请求进行拦截处理。

[0108] 具体地,在用户针对寄宿程序(小程序)的页面进行输入操作,如点击按钮控件等,该小程序的业务代码可以生成与该输入操作对应的业务请求,由于小程序的业务代码可以调用小程序内部的请求函数,如wx.request生成该业务请求,该业务请求可以包括业务服务器的地址。则运行环境可以监测该小程序的业务代码中对小程序请求函数的调用,以检测到与寄宿程序的页面关联的业务请求。进而将业务请求中的URL(业务服务器的地址)修改为与服务组件的地址同源的URL(即代理地址),使得服务组件可以拦截到该业务请求。示例性的,小程序的业务代码调用请求函数生成的业务请求中的URL为https: / / b.com / login,服务组件的地址https: / / a.com / sw.js,则运行环境可以将该业务请求中的URL修改为代理地址,如https: / / a.com / proxy?target=https: / / b.com / login,以达到同源(被服务组件拦截)的目的。

[0109] 其中,运行环境对业务请求中的URL的修改可以包括指示一个同源的代理服务器的地址的部分,如https: / / a.com / proxy?target=https: / / b.com / login中的https: / / a.com / proxy部分,在URL的"?”字符后,可以包括查询参数target,以"键=值”的形式出现,如target=ORIGINAL_URL,该ORIGINAL_URL会被替换成实际的原始请求URL,如https: / / b.com / login,以便代理服务器确定要将该业务请求转发到哪个业务服务器。由此,代理服务器在接收到服务组件转发的业务请求后,可以基于该业务请求执行相应的操作,即进一步发起代理请求。

[0110] 在一些实施例中,运行环境可以采用不同的方式检测与寄宿程序的页面关联的业务请求,并修改其中的URL。例如,运行环境可以在加载小程序的业务代码之前,在全局作用于中定义一个自定义的对象,并覆盖或包装wx.request方法,以使小程序的业务代码在调用wx.request函数时,可以被检测到并进行修改。再例如,运行环境可以使用某种形式的运行时钩子(如通过修改原型链)来替换或包装wx.request。又例如,运行环境可以通过JavaScript的某些特性(如Object.defineProperty)来拦截对wx.request的访问和调用。也就是说,运行环境在iframe注入小程序的业务代码之前,配置必要的钩子或者代理来拦截或者修改wx.request,相当于侵入业务代码中的wx.request(hack业务代码中的wx.request),进而在小程序的业务代码被加载到iframe中执行的过程中,调用wx.request函数时,由于之前设置的钩子或者代理,将检测到业务请求,并将业务请求中的URL修改为与服务组件的地址同源的URL。

[0111] 其中,小程序的业务代码在生成输入操作对应的业务请求后,运行环境可以在检测到业务请求并对其内部的URL进行修改的过程中,还可以将其转换为调用fetch应用程序编程接口(Application Programming Interface,API)的业务请求,即运行环境可以使用fetch API执行该业务请求。进而,服务组件可以通过监测fetch事件,以拦截和处理通过fetchAPI发起的业务请求。该fetch事件是服务组件(Service Workers)提供的一种机制,使得开发者能够在业务请求实际发送到代理服务器之前对其进行干预。具体地,当寄宿程序的页面(如小程序页面所对应的业务代码)尝试发起一个业务请求时,浏览器会检查是否有对应的服务组件监测该域名(地址)的fetch事件。如果有,浏览器可以将该业务请求的控制权交给服务组件,允许服务组件进一步处理这个请求。在本申请实施例中,在浏览器检测到所包含的地址与服务组件的地址同源的业务请求后,可以通过服务组件对该业务请求进行拦截处理,并将拦截到的业务请求转发至该代理服务器。

[0112] 进一步地,代理服务器可以接收该业务请求,具体可以通过监测请求(request)对象的data和end事件来获取来自服务组件的业务请求(请求数据)。data事件是request对象上的一个事件,它会在请求体(body)的数据块到达时被触发。代理服务器通过监测data事件,可以接收到来自服务组件的请求体数据。这些数据可能是分块发送的,所以data事件可能会被触发多次,每次触发都会传递一个数据块,即二进制数据流格式(buffer)对象。end事件也是request对象上的一个事件,它会在请求体的所有数据都已经接收完毕时被触发。这意味着当end事件被触发时,代理服务端已经接收到了来自服务组件的完整请求体数据。由此,代理服务器可以接收到完整的业务请求,并获取到诸如URL、请求头以及请求体中原始的请求参数,以便代理服务器知道要向哪个业务服务器发起请求,以及如何处理这个请求。

[0113] 进而,代理服务器可以根据接收到的业务请求中的URL和请求数据,如指示请求方法、请求的元信息等,向业务服务器发送生成的代理业务请求,在这个过程中,代理服务器会将接收到的业务请求的请求头和请求参数(即请求体)发送至该URL指示的业务服务器。在业务服务器基于代理业务请求进行处理后,如获取到请求方法所对应的数据或结果后,可以返回代理服务器与该代理业务请求对应的业务响应头和业务响应体。代理服务器可以接收业务服务器返回的业务响应头和业务响应体。

[0114] 在一种可能的实现方式中,在浏览器通过服务组件对业务请求进行拦截处理之前,可以先注册该服务组件,注册(Registration)可以理解为服务组件的生命周期中的第一个阶段。具体可以是在浏览器加载寄宿程序的页面之前,浏览器响应于目标页面的加载请求,获取目标页面对应的脚本文件,脚本文件中包括服务组件的注册脚本,注册脚本指示服务组件的地址和控制范围。进而浏览器可以运行脚本文件,以对目标页面进行加载处理,并基于服务组件的地址获取服务组件的安装文件。其中,注册服务组件是指通过一个页面(如目标页面)的脚本向浏览器请求注册一个服务组件脚本文件的过程,该脚本文件可以是JavaScript脚本文件,如sw.js,包含了服务组件(Service Worker)拦截业务请求,对响应进行处理的逻辑。

[0115] 其中,目标页面可以是其脚本文件中包含服务组件的注册脚本的页面,例如与运行环境关联的网页的页面。该服务组件的注册脚本可以是包括调用navigator.serviceWorker.register()方法的代码,该方法指定两个参数,第一个参数是服务组件的地址,也即是服务组件的脚本文件的路径(URL)。需要说明的是,由于服务组件运行在浏览器,其也受同源策略的限制,因此,服务组件的地址必须与所要控制的页面同源,如服务组件的地址为https: / / a.com / sw.js,所想要控制的页面的地址为https: / / a.com / xxxx,则服务组件可以将该想要控制的页面的地址设置为其控制范围内,以被其控制。第二个参数是scope,用于指示服务组件的控制范围,即该服务组件的脚本文件所能影响的作用域范围。需要说明的是,服务组件的作用域受限于其所在的目录,也就是说它只能对在其目录下的页面进行控制,如监测业务请求、拦截业务请求等。

[0116] 为了让服务组件能够对更多业务请求进行监测和拦截,可以指定该服务组件的scope参数为网站的根目录。也就是说,该参数可以指定将Service Worker的脚本放在网站的根目录,如https: / / a.com / sw.js,根目录为https: / / a.com,相当于将服务组件注册到https: / / a.com下,服务组件就可以拦截https: / / a.com下的所有业务请求。可以理解的是,若将服务组件脚本注册在较低层级的目录,如https: / / a.com / xxx / xxx,则该服务组件仅能处理该目录及其子目录下的业务请求。其中,调用navigator.serviceWorker.register()方法指定服务组件的地址和控制范围的代码可以是:navigator.serviceWorker.register(swUrl,scope:'. / '}),swUrl为指定的服务组件(serviceWorker)的地址,可以被替换为具体的URL,scope参数中的'. / '可以指示网站的根目录,如https: / / a.com。

[0117] 具体地,用户可以在浏览器的网址输入框中输入目标页面的URL,以触发该目标页面的加载请求,浏览器响应于该加载请求,可以基于该URL生成一个HTTP请求,并与该URL所指示的服务器建立通信连接,进而可以向服务器发送该HTTP请求,以请求特定的资源,如获取目标页面对应的脚本文件,以接收服务器返回的脚本文件,如HTML文件、JavaScript脚本文件。进而,浏览器可以运行该脚本文件,以基于该脚本文件的指示对目标页面进行渲染和输出,以完成对目标页面的加载处理。由于该脚本文件中包括服务组件的注册脚本,则浏览器可以基于注册脚本中服务组件的地址,获取该服务组件的安装文件。其中,浏览器基于服务组件的地址获取服务组件的安装文件,可以是向服务组件的地址(URL)指示的服务器发送安装文件的获取请求,以接收该服务器返回的安装文件,服务组件(Service Worker)的脚本文件(如sw.js)。由此,该服务组件(Service Worker)注册完成。

[0118] 在浏览器下载该服务组件的安装文件后,浏览器可以基于安装文件部署服务组件,并触发服务组件对控制范围内的页面所关联的业务请求进行监测处理。具体地,一旦该服务组件的安装文件(如Service Worker的脚本文件)被下载到浏览器,浏览器就会触发安装(install)事件,以指示服务组件进入生命周期中的安装阶段,即浏览器可以运行该安装文件,具体运行该安装文件中的脚本,触发安装(install)事件,进而执行初始化操作,如使用caches.open()和cache.addAll()等方法缓存静态资源、初始化数据库连接或设置其他必要状态的操作。在安装阶段,浏览器可以运行服务组件的安装文件,以注册监测器,以便监测未来的fetch、message、push等事件。可以理解的是,浏览器在服务组件的安装过程中发生错误,例如脚本执行错误等,该服务组件的安装会被终止,进而该服务组件不会进入激活阶段,即该服务组件不会被浏览器运行,无法处理业务请求或执行其他后台任务。

[0119] 在浏览器基于该安装文件成功安装完成后,服务组件需要被激活后才能用于控制所指示的作用于域的页面。因此,浏览器可以触发激活(activate)事件,以指示服务组件进入生命周期中的激活(Activation)阶段,以执行清理旧缓存、更新资源任务(更新缓存)等操作,以保证服务组件能够正确地控制页面。可以理解的是,在服务组件初次注册后,可以在基于安装文件对服务组件进行安装处理后,立即进入激活阶段。而只有激活成功的服务组件才能接管其作用域的控制权,即接管其控制范围内的页面以及处理这些页面的业务请求(如拦截业务请求)和其他任务,如对接收到业务请求对应的响应信息进行处理。由此,服务组件被部署完成。

[0120] 在浏览器基于该安装文件成功部署服务组件(即成功激活)后,可以进入其生命周期的控制(Control)阶段。该服务组件可以基于其安装文件的脚本中被配置的功能对其控制范围内的页面进行控制处理。如触发服务组件拦截和处理其控制范围内的页面发出的业务请求,即触发服务组件对控制范围内的页面所关联的业务请求进行监测处理,以进一步进行拦截和转发,具体可以通过监测fetch事件来实现。浏览器还可以通过服务组件接收和处理来自其控制范围内的页面的消息,页面可以通过postMessage方法发送消息给服务组件,而服务组件则通过监测message事件来实现接收这些消息。这使得页面和服务组件之间可以进行通信,例如,页面可以请求服务组件更新缓存,或者服务组件可以通知页面某些资源已经更新。

[0121] 在一种可能的实现方式中,目标页面可以是包括至少一个候选寄宿程序分别对应的控件,该目标页面可以输出至少一个候选寄宿程序的功能信息(简介信息),以接收用户针对其中一个候选寄宿程序的控件的触发操作,如用户可以针对目标页面中寄宿程序对应控件输入触发操作,以选择在浏览器中运行的寄宿程序。可以理解的是,该目标页面可以是小程序的菜单页面,可以显示至少一个小程序的控件和介绍,用户可以在目标页面中选择一个小程序,触发浏览器运行用户所选的小程序,以加载该小程序的页面。具体地,浏览器响应于针对目标页面中寄宿程序对应控件的触发操作,从与运行环境关联的服务器中获取寄宿程序的资源文件,并基于资源文件加载寄宿程序的页面。

[0122] 其中,寄宿程序对应控件是指目标页面中包括的至少一个候选寄宿程序分别对应的控件中,用户所选的一个候选寄宿程序对应的控件。用户可以通过点击等方式输入该触发操作。进而,浏览器可以向与运行环境(如Browser-Runtime)关联的服务器发送针对该寄宿程序的资源文件的获取请求,以接收该服务器返回的资源文件。进而可以基于该资源文件加载寄宿程序的页面。请一并参阅图5,图5是本申请实施例提供的一种目标页面的用户界面示意图,如图5所示,该目标页面中可以包括至少一个候选寄宿程序的名称,如微信开放社区、小程序助手、生活缴费、购物小程序、表单小程序以及快递小程序等。该目标页面中还包括至少一个候选寄宿程序的功能信息(简介信息),如微信开放社区的功能信息为提供小程序和公众号相关的开发服务等。该目标页面中可以包括至少一个候选寄宿程序图标(logo),以及提供寄宿程序服务的企业主体,如xxxxx企业,还可以包括其他信息,本申请对此不做限定。

[0123] 可以理解的是,在图5所示的目标页面中,每个方框中的内容可以是一个候选寄宿程序所对应的控件,用户可以在该目标页面中点击其中一个候选寄宿程序对应控件,如表单小程序,以输入触发操作。该表单小程序对应一个小程序标识(appid),进而浏览器可以将该将该小程序标识(appid)传入运行环境中的组件,运行环境中的组件可以创建多个框架(iframe),并向与运行环境关联的服务器请求该小程序标识所指示的资源文件,如小程序的业务代码和小程序的基础库,并将请求到的小程序业务代码和小程序的基础库注入到对应的iframe中,从而浏览器可以运行该表单小程序,加载该表单小程序的用户界面,使得浏览器可以输出如图4所示的小程序的用户界面。

[0124] S302、代理服务器对上述业务响应头进行编码处理,并根据编码处理得到的编码响应头构建目标响应头。

[0125] 在本申请实施例中,代理服务器在获取到业务服务器反馈的与业务请求关联的业务响应头和业务响应体之后,可以进一步对该业务响应头进行处理,例如进行编码处理,得到的编码结果可以称为编码响应头,该编码处理可以理解为加密处理,对侧(浏览器)在接收到编码处理后得到的编码响应头进行解密。代理服务器构建的目标响应头可以是指代理服务器所构建的响应头,用于向浏览器发送业务请求对应的响应信息。其中,代理服务器对所述业务响应头进行编码处理的方式可以是Base64格式,Base64是一种基于64个可打印字符来表示二进制数据的表示方法。代理服务器对业务响应头进行编码处理可以理解为代理服务器将业务响应头编码为Base64格式,即将业务响应头中的文本信息(业务响应头中的字符)转换为Base64编码的字符串。

[0126] 需要说明的是,由于代理服务器获取到的业务响应头可能是受到黑客攻击的,因此,该业务响应头中可能包含非法、恶意文字。由于代理服务器是企业部署的服务器,为了防止代理服务器传输包括非法、恶意的文字,防止潜在的攻击或者恶意内容直接被传递至浏览器,以及避免企业因传输有害内容而可能面临的法律责任,代理服务器可以在接收到业务响应头后对其进行编码处理,将其编码为Base64格式。其中,代理服务器可以调用编程语言提供的库或API来实现对想要编码的信息进行编码,例如,代理服务器可以调用btoa函数来对业务响应头进行编码,得到编码结果,即编码响应头,该编码响应头中包括进行编码处理得到的字符串。

[0127] 进一步地,该代理服务器可以根据编码处理得到的编码响应头构建目标响应头。具体地,代理服务器可以将编码响应头存储在预定义响应头中,并生成用于指示客户端访问预定义响应头的解析信息,进而根据预定义响应头和解析信息,构建目标响应头。其中,预定义响应头是指一个预先定义的响应头,也可以理解为一个预定义的字段,该字段可以称为响应头字段(Response Headers),响应头字段是指可以用于指示响应信息的元数据,有助于确保请求响应的客户端对响应进行正确处理。将编码响应头存储在预定义响应头中,是指代理服务器将编码响应头作为该预定义响应头字段的值,例如该预定义响应头为runtime-safe-proxy-heads,则代理服务器可以将编码响应头存储到runtime-safe-proxy-heads中,以作为runtime-safe-proxy-heads字段的值。

[0128] 其中,解析信息可以用于指示客户端访问预定义响应头,也可以理解为允许客户端(浏览器)访问该字段和字段的值,或者仅允许访问该字段和字段的值。该解析信息也可以理解为一个字段,可以设置该字段的值,以指示浏览器访问预定义响应头。代理服务器根据预定义响应头和解析信息构建目标响应头可以是指代理服务器将预定义响应头(字段)和解析信息(字段)作为目标响应头的字段,以得到目标响应头。需要说明的是,代理服务器在构建目标响应头的过程中,还可能包括其他字段(响应头),如指示响应生成的日期和时间的Date字段,以及用于在客户端存储和传递代理服务器设置的Cookie信息的Set-Cookie字段,通过设置Cookie,代理服务器可以在客户端跟踪用户的会话状态等等。解析信息可以指示客户端(浏览器)仅允许访问预定义响应头字段和该字段的值,例如,解析信息可以是Access-Control-Expose-Headers,其值为runtime-safe-proxy-heads,可以指示浏览器只能访问runtime-safe-proxy-heads响应头,从而可以防止浏览器访问不属于自己的敏感响应头,如Set-Cookie响应头。

[0129] 进一步地,在代理服务器根据预定义响应头和解析信息构建目标响应头的过程中,还可以生成用于指示特定传输格式的内容类型信息,并根据内容类型信息、预定义响应头和解析信息,构建目标响应头。由于到达浏览器的响应信息不能是浏览器可立即执行的文件,因此代理服务器可以将响应体以二进制流数据格式(buffer)的形式发送至浏览器。在响应体需要以二进制流数据格式(buffer)的形式发送至浏览器的情况下,代理服务器可以生成用于指示所述特定传输格式的内容类型信息,该内容类型信息与解析信息类似,可以是一个响应头字段,如内容类型(content-type)字段,其值为application / octet-stream,用于表示响应体是二进制数据流(buffer流),没有特定的格式或文件类型,而是表示数据是以二进制形式存在的,即该内容类型信息可以用于告知浏览器代理服务器返回的是一个stream数据流。进而,代理服务器可以根据内容类型信息、预定义响应头和解析信息构建目标响应头,可以是指代理服务器将预定义响应头(字段)、解析信息(字段)、内容类型信息(字段)作为目标响应头的字段,以得到目标响应头。

[0130] 进一步地,代理服务器还可以对获取到的业务响应头中的特定字段进行检查,若检查出业务响应头包括特定字段,则基于特定字段和特定字段所对应的值,生成响应属性信息,进而代理服务器可以根据响应属性信息、内容类型信息、预定义响应头,以及解析信息,构建目标响应头。其中,特定字段可以是业务响应头中用于指示客户端正确解析和处理业务响应体的字段,也可以称为响应头字段,如响应数据压缩格式的字段"content-encoding”和响应数据的内容长度的字段"content-length”,还可以包括其他响应头字段,本申请对此不做限定。由于业务响应头被编码处理,因此代理服务器可以生成用于包括特定字段和其对应的值的响应属性信息,以兼容所有业务接口的响应类型,并告知浏览器该代理服务器返回的响应信息中响应体的压缩格式和响应体的内容长度。例如,该响应属性信息可以包括content-encoding:gzip,Content-Length:348,则该响应属性信息可以用于告知浏览器该响应体使用gzip压缩,且有348个字节。进而,代理服务器也可以将该响应属性信息中的字段作为目标响应头中的字段,从而构建出目标响应头。

[0131] 在一些实施例中,在代理服务器中的脚本中,构建目标响应头的顺序可以由开发人员为代理服务器编写的脚本所确定,本申请对此不做限定。示例性的,代理服务器可以首先生成用于指示特定传输格式的内容类型信息,进而对业务响应头中的特定字段进行检查,若检查出业务响应头包括特定字段,则基于特定字段和特定字段所对应的值,生成响应属性信息。然后,代理服务器可以将业务响应头进行编码,得到编码响应头,并将其存储在预定义响应头中,并设置用于指示客户端访问该预定义响应头的解析信息。由此,代理服务器得到构建出的目标响应头。

[0132] S303、代理服务器将上述业务响应体转换为特定传输格式,得到目标响应体,并根据上述目标响应头和上述目标响应体生成目标响应信息。

[0133] 在本申请实施例中,特定传输格式可以是指二进制流数据格式(buffer),该特定传输格式的业务响应体可以称为目标响应体。需要说明的是,代理服务器没有对业务响应体的内容进行任何的处理,仅是对其传输格式进行指定。具体地,代理服务器可以调用response.end()方法,如通过res.end(buffer)指定了业务响应体为buffer对象,该对象包含了要发送给客户端的二进制数据,该对象也就是目标响应体,该该对象包含的内容即为业务响应体中的内容。其中,目标响应信息是指由目标响应头和目标响应体所构建的一个完整的HTTP响应,代理服务器是先构建完整的响应(包括响应头和响应体),然后一次性发送给客户端。也就是说,代理服务器可以将目标响应头和目标响应体进行组合,以构建完整的响应(目标响应信息),进而一次性以buffer(流)的形式传输给客户端。

[0134] S304、代理服务器将上述目标响应信息发送至客户端。相应的,客户端接收代理服务器针对业务请求返回的目标响应信息。

[0135] 其中,代理服务器将处理后的响应信息,即目标响应信息通过与客户端之间的通信连接发送至客户端,客户端可以通过该通信连接接收代理服务器针对业务请求返回的目标响应信息。

[0136] S305、客户端对上述编码响应头进行解码处理,并基于上述目标响应体和解码处理得到的响应头生成业务响应信息。

[0137] 在本申请实施例中,客户端在接收到该目标响应信息后,可以对该目标响应信息进行解析处理,得到目标响应信息中的目标响应头和目标响应体,该目标响应头包括代理服务器对获取到的业务响应头进行编码所生成的编码响应头,该目标响应体可以是代理服务器将获取到的业务响应体指定了特定传输格式得到的。在客户端对该目标响应信息进行解析后,可以得到该目标响应头中解析信息,如Access-Control-Expose-Headers,其值为runtime-safe-proxy-heads,由此,客户端可以确定所要访问的预定义响应头为runtime-safe-proxy-heads,并访问该解析信息指示的预定义响应头(runtime-safe-proxy-heads),以访问到存储在该预定义响应头中的编码响应头。

[0138] 进而,客户端可以基于预设解码方式对所述编码响应头进行解码处理,该解码处理是指对经过Base64编码得到的字符串进行Base64解码。具体地,客户端可以通过内置的JavaScript函数来进行Base64解码处理,如调用atob()函数用于Base64解码。需要说明的是,由于业务请求是由服务组件转发到代理服务器的,因此代理服务器在返回目标响应信息时,可以是返回到服务组件,进而客户端可以通过服务组件对该目标响应信息进行解析,进而对该编码响应头进行解码处理。可以理解的是,由于该目标响应信息到达浏览器时,不是一个浏览器可立即执行的文件,则浏览器不会立即执行,一方面有效的防止黑客利用运行环境的同源特性和业务请求的代理能力向运行环境的同源页面(iframe,如AppService层的业务代码)注入恶意脚本,以获取敏感信息等攻击,另一方面,保证了企业内部代理服务器返回到的内容仅是一个二进制流数据(buffer)而不是一个可能的非法、恶意文字,可以防止潜在的攻击或者恶意内容直接被传递至浏览器,也可以避免企业因传输有害内容而可能面临的法律责任。

[0139] 在这种情况下,由于浏览器中的寄宿程序的页面还需业务服务器返回的响应(业务响应头和业务响应体)对该寄宿程序的页面执行业务请求对应的响应处理,因此,服务组件可以基于目标响应体和解码处理得到的响应头生成业务响应信息,该业务响应信息即为用于返回运行环境中该寄宿程序的业务代码(如AppService层的业务代码)的响应信息,以使该业务代码执行相应的响应处理。也就是说,该服务组件可以在接收到目标响应信息后,构造了一个新的响应信息,即业务响应信息,并将该业务响应信息返回至运行环境,以返回至寄宿程序的业务代码(如AppService层的业务代码)。

[0140] 具体地,服务组件可以将对编码响应头进行解码处理得到的响应头作为业务响应信息中的响应头,进而服务组件可以基于解码处理得到的响应头中指示的内容类型,即基于Content-Type字段的值对该目标响应体(二进制数据)进行格式转换,将其转换为可读或者可用的格式。示例性的,若解码处理得到的响应头中的Content-Type字段的值为application / json,则服务组件可以将目标响应体的buffer流转换成JSON对象,具体可以调用JSON.parse()方法进行转换。若该Content-Type字段的值image / jpeg,则服务组件可以将目标响应体的buffer流转换成图像等。由此,服务组件可以将解码处理得到的响应头和格式转换后的响应体作为业务响应信息返回至运行环境。可以理解为,服务组件可以将目标响应信息(buffer)转换为原本的数据结构返回至运行环境,具体可以返回至运行环境中寄宿程序的业务代码,以返回AppService层的业务代码真正的响应。

[0141] S306、客户端基于上述业务响应信息对上述业务请求进行响应处理。

[0142] 在本申请实施例中,业务响应信息为客户端中的服务组件构建的响应信息,可以包括解码处理得到的响应头和格式转换后的响应体。客户端基于业务响应信息对业务请求进行响应处理,可以是指客户端中的运行环境中运行的寄宿程序的业务代码,可以基于业务响应信息对用于针对寄宿程序的页面的输入操作进行响应处理。例如,用户点击了一个控件用于表单提交,则业务响应信息的响应体中可以包括表单提交的结果,进而该业务代码可以将该表单提交的结果输出至该寄宿程序的页面中。再例如,用户点击了一个控件用于显示图像,则业务响应信息的响应体中可以包括该图像,进而该业务代码可以触发加载该图像,将该图像出至该寄宿程序的页面中,以向用户展示。

[0143] 在一种可能的实现方式中,该寄宿程序的业务程序中编写了该寄宿程序的业务逻辑,当业务代码接收到业务响应信息后,可以基于与业务请求关联的业务逻辑确定业务请求与业务响应信息是否匹配,若确定业务请求与业务响应信息不匹配,则客户端可以基于业务响应信息进行报错处理,即该业务代码可以进行报错处理。可以理解的是,业务代码仅会在返回的业务响应信息与其业务逻辑匹配的情况下,才能执行对应的响应处理,如果数据出现问题,如植入了恶意脚本,则业务代码无法基于恶意脚本进一步执行,则业务代码会进行报错。其中,业务代码的业务逻辑可以是该寄宿程序的开发者所编写的,具体可以基于不同寄宿程序的应用场景、开发逻辑、以及不同寄宿程序所对应的企业确定,本申请对此不做限定。业务代码的业务逻辑可以用于对接收到的业务响应信息进行匹配,与业务请求关联的业务逻辑为业务代码的业务逻辑中的一部分。也就是说,寄宿程序的业务代码只能在基于与业务请求关联的业务逻辑确定业务响应信息为业务请求所请求的响应信息时,才会进一步对该业务请求执行响应处理。

[0144] 需要说明的是,上述该目标响应信息中的目标响应体不是一个可立即执行的文件,可以让浏览器在接收到响应后不立即执行,可以理解为暂时保证运行环境的同源页面不受到攻击。服务组件将目标响应信息转换为业务响应信息后传输给寄宿程序的业务代码,可以进一步通过业务代码判断业务响应信息与业务请求的业务逻辑是否匹配,若不匹配,表示业务响应请求包括恶意脚本,并非所请求的响应信息,则进行报错,从而使得恶意脚本彻底失效,以使黑客利用运行环境的同源特性和请求代理的能力进行XSS攻击达不到攻击的效果。

[0145] 在一种可能的实现方式中,在客户端触发服务组件对其控制范围内的页面所关联的业务请求进行监测处理之后,即客户端触发服务组件对其控制范围内的页面进行控制的过程中,客户端可以接收用户针对目标页面的重新加载操作,生成针对目标页面的重新加载请求,该重新加载操作例如可以是刷新操作,如强制刷新操作,或者基于浏览器提供的刷新控件输入的刷新操作。客户端响应于该重新加载请求,可以再次获取该目标页面的脚本文件。由于该脚本文件中包括所述服务组件的注册脚本,则在浏览器再次运行获取到的脚本文件时,可以对该目标页面进行重新加载处理。并且,在运行脚本文件时,也运行了注册脚本,因此客户端可以基于注册脚本指示的服务组件的地址获取服务组件的更新安装文件。具体获取过程与初次获取安装文件的过程相同,此处不再赘述。

[0146] 进而,客户端可以比较初次获取到的安装文件和本次获取到的更新安装文件,来自动检测安装文件是否有更新。具体可以分别计算两次获取到的两个安装文件的哈希值,在确定计算出的哈希值不同的情况下,客户端可以确定更新安装文件相较于安装文件有更新,则该客户端可以基于更新安装文件对服务组件进行更新处理。可以理解的是,客户端获取更新安装文件的过程可以是新版本的服务组件的生命周期的注册阶段,也可以理解为旧版本的服务组件的生命周期的更新(update)阶段。进而,客户端可以基于该更新安装文件进行安装处理,得到更新服务组件,运行该更新安装文件中的脚本,触发安装(install)事件,执行新版本的服务组件的初始化操作,以得到部署的更新服务组件。

[0147] 需要说明的是,在基于更新安装文件进行安装处理后,可以等待激活该更新服务组件,这是由于浏览器需要先检测服务组件(即旧版本的服务组件)控制的页面是否全部关闭,即浏览器可以检测服务组件的控制范围内的页面是否已关闭,在检测出已关闭的情况下,才可以激活该更新服务组件,以触发更新服务组件对控制范围内的页面进行控制,如对控制范围内的页面所关联的业务请求进行监测处理。可以理解的是,在更新服务组件在安装的过程中,若服务组件(即旧版本的服务组件)所控制的页面并未全部关闭,如服务组件仍然会控制着当前页面,则更新服务组件需一直等待,直至服务组件所控制的页面关闭后,即释放控制权后,才能被激活。相较于激活服务组件,浏览器激活更新服务组件可以执行诸如更新服务组件缓存的静态资源、清理服务组件缓存的不需要的旧缓存等操作。

[0148] 其中,浏览器检测服务组件的控制范围内的页面是否已关闭可以是指浏览器可以跟踪服务组件的控制范围内的页面是否已关闭,浏览器可以基于服务组件的控制范围,以及浏览器当前加载(开启)的至少一个页面的地址,确定该至少一个页面中是否在服务组件的控制范围内的页面,若存在,则浏览器检测到服务组件的控制范围内的页面没有关闭,反之,若不存在,则浏览器检测到服务组件的控制范围内的页面已关闭。由此,浏览器可以确定更新服务组件的激活时机,以触发更新服务组件接管对控制范围内的页面的控制权。

[0149] 在一些实施例中,若客户端可以确定更新安装文件相较于安装文件没有更新,则客户端可以不进行更新处理,即继续通过服务组件对其控制范围内的页面进行控制。

[0150] 在一种可能的实现方式中,若更新服务组件成功被激活用于控制其控制范围内的页面,则服务组件会被自动终止,即停止该服务组件(线程)的运行,不再执行任何代码或者处理任何时间,并释放其所占用的系统资源,如内存、中央处理器(Central ProcessingUnit,CPU)等资源将被释放,以便其他应用或进程使用。

[0151] 在另一种可能的实现方式中,在客户端一直通过服务组件对其控制范围内的页面进行控制的场景中,若客户端在预设时长范围内未检测到与控制范围内的页面关联的业务请求,则客户端可以停止运行该服务组件。可以理解的是,浏览器可以在服务组件空闲时将其终止,即该服务组件进入生命周期中的终止(Termination)阶段,以节约资源,如停止运行该服务组件的线程所释放出的内存、CPU等资源。在停止运行该服务组件之后,若客户端检测到控制范围内的页面中,与服务组件的地址同源的新增业务请求,则客户端可以重新运行服务组件,并通过服务组件对新增业务请求进行拦截处理。

[0152] 也就是说,浏览器在停止运行该服务组件之后,服务组件安装之前缓存的资源(如通过Cache方法缓存的文件)仍然保留在浏览器中,浏览器可以在检测到控制范围内的页面中,与服务组件的地址同源的新增业务请求后,重新启动服务组件,以通过服务组件执行相应的控制处理,如通过该服务组件对浏览器所检测到的新增业务请求进行拦截处理。其中,浏览器检测到控制范围内的页面中,与服务组件的地址同源的新增业务请求,可以是浏览器在受控页面生成业务请求息时,浏览器会触发响应的事件,如fetch事件,则浏览器可以检测到与控制范围内的页面中关联的新增业务请求,从而可以重新运行该服务组件,具体可以尝试重用之前的实例,以快速回复其的控制权,以对新增业务请求进行拦截处理。

[0153] 请一并参阅图6,图6是本申请实施例提供的一种代理业务请求的架构示意图,如图6所示,相较于图1,在客户端(浏览器)中新增(部署)了服务组件,可以用于拦截从运行环境发出的业务请求(request),并对其进行代理,如生成代理业务请求(request)后发送至代理服务器,代理服务器接收该代理业务请求后,可以基于代理业务请求所指示的业务接口进行代理(proxy),如从向业务接口指示的业务服务器发送代理业务请求,并接收业务服务器返回的业务响应头和业务响应体。进而,代理服务器可以将业务响应体转换为特定传输格式,如二进制流数据格式,并对业务响应头进行编码处理构建目标响应头。进而将目标响应头和转换格式后得到的目标响应体作为目标响应信息返回至浏览器,由于目标响应体是buffer流的格式,则该目标响应信息可以理解为bufferresponse。

[0154] 进而,代理服务器返回的目标响应信息可以由服务组件(ServiceWorker)接收,并将其转换为用于运行环境中寄宿程序的业务代码进行响应处理的业务响应信息。具体可以对目标响应头中的编码处理得到的编码响应头进行解码处理,并基于解码得到的响应头所指示的内容类型对buffer格式的目标响应体进行格式转换处理,从而基于解码处理的响应头和格式转换后的目标响应体构建业务响应信息,进而将业务响应信息返回至运行环境,具体返回至运行环境运行的寄宿程序(如小程序)的业务代码,以使该业务代码基于业务响应信息执行响应处理。可以理解的是,若该业务响应信息中不包括黑客篡改后获取到的恶意脚本,则该业务响应信息可以看作为一个safe response。在上述浏览器和代理服务器的交互过程中,用户全程是无感知的,仅能基于浏览器展示的用户界面与寄宿程序进行交互。

[0155] 在本申请中的一些实施例所提供的技术方案中,代理服务器通过将获取到的业务响应头进行编码处理,并将业务响应体转换为特定传输格式,以将编码后的响应头和格式转换后的响应体作为目标响应信息发送至客户端。客户端可以对编码响应头进行解码处理,并基于目标响应体和解码处理得到的响应头生成业务响应信息,进而客户端可以基于业务响应信息对所运行的运行环境中运行的小程序的业务请求进行响应处理。由此可见,在该目标响应信息返回至客户端中的浏览器时,由于该目标响应信息中的目标响应体并非是浏览器可立即执行的文件,而是特定传输格式的数据,在浏览器接收到该目标响应信息后不会立即执行该可能包括恶意脚本的文件,有利于防止黑客利用同源策略的特性,将恶意脚本注入与运行环境同源的小程序的业务代码(iframe)中,从而保护了运行环境的同源页面不受到该恶意脚本的攻击,提高运行环境的同源页面的安全性。并且,代理服务器可以对获取到的业务响应头进行编码,以在业务响应头中包含恶意、非法文字时,防止恶意内容直接被传递至浏览器,进一步增强安全性。

[0156] 上述详细阐述了本申请实施例的方法,为了便于更好地实施本申请实施例的上述方案,相应地,下面提供了本申请实施例的装置。

[0157] 请参阅图7,图7是本申请实施例提供的一种业务请求的响应处理装置的结构示意图,该业务请求的响应处理装置70应用于客户端,可以用于执行图3所示的业务请求的响应处理方法中的相应步骤。该业务请求的响应处理装置70包括如下单元:

[0158] 接收单元701,用于接收代理服务器针对业务请求返回的目标响应信息,所述目标响应信息包括目标响应头和目标响应体,所述目标响应头包括所述代理服务器对获取到的业务响应头进行编码所生成的编码响应头,所述目标响应体是所述代理服务器将获取到的业务响应体转换为特定传输格式得到的;

[0159] 处理单元702,用于对所述编码响应头进行解码处理,并基于所述目标响应体和解码处理得到的响应头生成业务响应信息;基于所述业务响应信息对所述业务请求进行响应处理。

[0160] 在一种可能的实现方式中,该业务请求的响应处理装置70还包括:

[0161] 生成单元703,用于响应于接收到的针对指定应用程序页面的输入操作,生成所述输入操作对应的业务请求;

[0162] 发送单元704,用于向所述代理服务器发送所述业务请求,以使所述代理服务器从所述业务请求指示的业务服务器中获取所述业务响应头和所述业务响应体。

[0163] 在一种可能的实现方式中,所述指定应用程序包括寄宿程序,所述寄宿程序运行于宿主程序所提供的运行环境中,所述宿主程序中还运行有服务组件;所述发送单元704用于向所述代理服务器发送所述业务请求,具体用于:

[0164] 若检测到与所述寄宿程序的页面关联的业务请求,则通过所述运行环境将所述业务请求中包含的所述业务服务器的地址修改为与所述服务组件的地址同源的代理地址;

[0165] 若监测到所包含的地址与所述服务组件的地址同源的业务请求,则通过所述服务组件对所述业务请求进行拦截处理,并将拦截到的所述业务请求转发至所述代理服务器。

[0166] 在一种可能的实现方式中,该业务请求的响应处理装置70还包括:

[0167] 获取单元705,用于响应于目标页面的加载请求,获取所述目标页面对应的脚本文件,所述脚本文件中包括所述服务组件的注册脚本,所述注册脚本指示所述服务组件的地址和控制范围;

[0168] 运行单元706,用于运行所述脚本文件,以对所述目标页面进行加载处理,并基于所述服务组件的地址获取所述服务组件的安装文件;

[0169] 部署单元707,用于基于所述安装文件部署所述服务组件,并触发所述服务组件对所述控制范围内的页面所关联的业务请求进行监测处理。

[0170] 在一种可能的实现方式中,所述目标页面中包括至少一个候选寄宿程序分别对应的控件,所述获取单元,还用于响应于针对所述目标页面中所述寄宿程序对应控件的触发操作,从与所述运行环境关联的服务器中获取所述寄宿程序的资源文件,并基于所述资源文件加载所述寄宿程序的页面。

[0171] 在一种可能的实现方式中,所述获取单元705,还用于响应于针对所述目标页面的重新加载请求,再次获取所述脚本文件;

[0172] 所述运行单元706,还用于运行再次获取到的脚本文件,以对所述目标页面进行重新加载处理,并基于所述服务组件的地址获取所述服务组件的更新安装文件;

[0173] 所述处理单元702,还用于若所述更新安装文件相较于所述安装文件有更新,则基于所述更新安装文件对所述服务组件进行更新处理。

[0174] 在一种可能的实现方式中,所述处理单元702,用于基于所述更新安装文件对所述服务组件进行更新处理,具体用于:

[0175] 基于所述更新安装文件进行安装处理,得到更新服务组件;

[0176] 若检测到所述控制范围内的页面已关闭,则触发所述更新服务组件对所述控制范围内的页面所关联的业务请求进行监测处理。

[0177] 在一种可能的实现方式中,所述运行单元706,还用于若在预设时长范围内未检测到与所述控制范围内的页面关联的业务请求,则停止运行所述服务组件;

[0178] 在停止运行所述服务组件之后,若检测到所述控制范围内的页面中,与所述服务组件的地址同源的新增业务请求,则重新运行所述服务组件,并通过所述服务组件对所述新增业务请求进行拦截处理。

[0179] 在一种可能的实现方式中,所述目标响应头中还包含有解析信息,解析信息用于指示预定义响应头;

[0180] 所述处理单元702,用于对所述编码响应头进行解码处理,具体用于:

[0181] 访问所述解析信息指示的所述预定义响应头中存储的所述编码响应头;

[0182] 基于预设解码方式对所述编码响应头进行解码处理。

[0183] 在一种可能的实现方式中,所述处理单元702,用于基于所述业务响应信息对所述业务请求进行响应处理,具体用于:

[0184] 若基于与所述业务请求关联的业务逻辑确定所述业务请求与所述业务响应信息不匹配,则基于所述业务响应信息进行报错处理。

[0185] 根据本申请的一个实施例,图3所示的方法所涉及的步骤可以是由图7所示的业务请求的响应处理装置中的各个单元执行的。例如,图3所示的步骤S304由图7所示的接收单元701来执行,步骤S305和步骤S306均由图7所示的处理单元702来执行。

[0186] 根据本申请的一个实施例,图7所示的业务请求的响应处理装置70中的各个单元可以分别或全部合并为一个或若干个另外的单元来构成,或者其中的某个(些)单元还可以再拆分为功能上更小的多个单元来构成,这可以实现同样的操作,而不影响本申请的实施例的技术效果的实现。上述单元是基于逻辑功能划分的,在实际应用中,一个单元的功能也可以由多个单元来实现,或者多个单元的功能由一个单元实现。在本申请的其它实施例中,该业务请求的响应处理装置70也可以包括其它单元,在实际应用中,这些功能也可以由其它单元协助实现,并且可以由多个单元协作实现。根据本申请的另一个实施例,可以通过在包括例如中央处理单元(CPU)、随机存取存储介质(RAM)、只读存储介质(ROM)等处理元件和存储元件的通用计算机的通用计算设备上运行能够执行如图3中所示的相应方法所涉及的各步骤的计算机程序(包括程序代码),来构造如图7中所示的业务请求的响应处理装置70,以及来实现本申请实施例的业务请求的响应处理方法。计算机程序可以记载于例如计算机可读存储介质上,并通过计算机可读存储介质装载于图2所示业务请求的响应处理系统的用户设备201中,并在其中运行。

[0187] 请参阅图8,图8是本申请实施例提供的另一种业务请求的响应处理装置的结构示意图,该业务请求的响应处理装置80应用于服务器,可以用于执行图3所示的业务请求的响应处理方法中的相应步骤。该业务请求的响应处理装置80包括如下单元:

[0188] 获取单元801,用于获取业务服务器反馈的与业务请求关联的业务响应头和业务响应体;

[0189] 处理单元802,用于对所述业务响应头进行编码处理,并根据编码处理得到的编码响应头构建目标响应头;

[0190] 转换单元803,用于将所述业务响应体转换为特定传输格式,得到目标响应体,并根据所述目标响应头和所述目标响应体生成目标响应信息;

[0191] 发送单元804,用于将所述目标响应信息发送至客户端,以使所述客户端对所述编码响应头进行解码处理,基于所述目标响应体和解码得到的响应头生成针对所述业务请求的业务响应信息。

[0192] 在一种可能的实现方式中,所述获取单元801,用于获取业务服务器反馈的与业务请求关联的业务响应头和业务响应体,具体用于:

[0193] 向所述业务请求指示的所述业务服务器发送基于所述业务请求生成的代理业务请求,所述业务请求是所述客户端响应于指定应用程序页面的输入操作生成并发送的;

[0194] 接收所述业务服务器返回的所述业务响应头和所述业务响应体。

[0195] 在一种可能的实现方式中,所述处理单元802,用于根据编码处理得到的编码响应头构建目标响应头,包括:

[0196] 将所述编码响应头存储在预定义响应头中,并生成用于指示所述客户端访问所述预定义响应头的解析信息;

[0197] 根据所述预定义响应头和所述解析信息,构建所述目标响应头。

[0198] 在一种可能的实现方式中,所述处理单元802,用于根据编码处理得到的编码响应头构建目标响应头,包括:

[0199] 根据所述预定义响应头和所述解析信息,构建所述目标响应头,包括:

[0200] 生成用于指示所述特定传输格式的内容类型信息;

[0201] 根据所述内容类型信息、所述预定义响应头和所述解析信息,构建所述目标响应头。

[0202] 在一种可能的实现方式中,所述处理单元802,用于根据编码处理得到的编码响应头构建目标响应头,包括:

[0203] 根据所述内容类型信息、所述预定义响应头和所述解析信息,构建所述目标响应头,包括:

[0204] 对所述业务响应头中的特定字段进行检查,若检查出所述业务响应头包括所述特定字段,则基于所述特定字段和所述特定字段所对应的值,生成响应属性信息;

[0205] 根据所述响应属性信息、所述内容类型信息、所述预定义响应头,以及所述解析信息,构建所述目标响应头。

[0206] 根据本申请的一个实施例,图3所示的方法所涉及的步骤可以是由图8所示的业务请求的响应处理装置中的各个单元执行的。例如,图3所示的步骤S301由图8所示的获取单元801来执行,步骤S302由图8所示的处理单元802来执行,步骤S303由图8所示的转换单元803来执行,步骤S304由图8所示的发送单元803来执行。

[0207] 根据本申请的一个实施例,图8所示的业务请求的响应处理装置80中的各个单元可以分别或全部合并为一个或若干个另外的单元来构成,或者其中的某个(些)单元还可以再拆分为功能上更小的多个单元来构成,这可以实现同样的操作,而不影响本申请的实施例的技术效果的实现。上述单元是基于逻辑功能划分的,在实际应用中,一个单元的功能也可以由多个单元来实现,或者多个单元的功能由一个单元实现。在本申请的其它实施例中,该业务请求的响应处理装置80也可以包括其它单元,在实际应用中,这些功能也可以由其它单元协助实现,并且可以由多个单元协作实现。根据本申请的另一个实施例,可以通过在包括例如中央处理单元(CPU)、随机存取存储介质(RAM)、只读存储介质(ROM)等处理元件和存储元件的通用计算机的通用计算设备上运行能够执行如图2、图4和图7中所示的相应方法所涉及的各步骤的计算机程序(包括程序代码),来构造如图8中所示的业务请求的响应处理装置80,以及来实现本申请实施例的业务请求的响应处理方法。计算机程序可以记载于例如计算机可读存储介质上,并通过计算机可读存储介质装载于图2所示业务请求的响应处理系统的代理服务器202中,并在其中运行。

[0208] 基于上述业务请求的响应处理方法实施例的描述,本申请实施例还公开一种电子设备,请参阅图9,该电子设备90至少可包括处理器901、输入设备902、输出设备903以及存储器904。其中,电子设备90内的处理器901、输入设备902、输出设备903以及存储器904可通过总线或其他方式连接。

[0209] 上述存储器904是电子设备90中的记忆设备,用于存放程序和数据。可以理解的是,此处的存储器904既可以包括业务请求的响应处理设备的内置存储介质,当然也可以包括电子设备90支持的扩展存储介质。存储器904提供存储空间,该存储空间存储了电子设备90的操作系统。并且,在该存储空间中还存放计算机程序(包括程序代码)。需要说明的是,此处的计算机存储介质可以是高速RAM存储器;可选的,还可以是至少一个远离前述处理器的计算机存储介质、上述处理器可以称为中央处理单元(Central Processing Unit,CPU),是业务请求的响应处理设备的核心以及控制中心,用于运行上述存储器904中存储的计算机程序。

[0210] 在一种实施方式中,可由处理器901加载并执行存储器904中存放的计算机程序,以实现上述有关业务请求的响应处理方法实施例中的方法的相应步骤;具体的,上述处理器901加载并执行存储器904中存放的计算机程序,用于:

[0211] 接收代理服务器针对业务请求返回的目标响应信息,所述目标响应信息包括目标响应头和目标响应体,所述目标响应头包括所述代理服务器对获取到的业务响应头进行编码所生成的编码响应头,所述目标响应体是所述代理服务器将获取到的业务响应体转换为特定传输格式得到的;

[0212] 对所述编码响应头进行解码处理,并基于所述目标响应体和解码处理得到的响应头生成业务响应信息;

[0213] 基于所述业务响应信息对所述业务请求进行响应处理。

[0214] 在一种可能的实现方式中,所述处理器901加载并执行存储器904中存放的计算机程序,还用于:

[0215] 响应于接收到的针对指定应用程序页面的输入操作,生成所述输入操作对应的业务请求;

[0216] 向所述代理服务器发送所述业务请求,以使所述代理服务器从所述业务请求指示的业务服务器中获取所述业务响应头和所述业务响应体。

[0217] 在一种可能的实现方式中,所述指定应用程序包括寄宿程序,所述寄宿程序运行于宿主程序所提供的运行环境中,所述宿主程序中还运行有服务组件;所述处理器901加载并执行存储器904中存放的计算机程序,用于向所述代理服务器发送所述业务请求,具体用于:

[0218] 若检测到与所述寄宿程序的页面关联的业务请求,则通过所述运行环境将所述业务请求中包含的所述业务服务器的地址修改为与所述服务组件的地址同源的代理地址;

[0219] 若监测到所包含的地址与所述服务组件的地址同源的业务请求,则通过所述服务组件对所述业务请求进行拦截处理,并将拦截到的所述业务请求转发至所述代理服务器。

[0220] 在一种可能的实现方式中,所述处理器901加载并执行存储器904中存放的计算机程序,还用于:

[0221] 响应于目标页面的加载请求,获取所述目标页面对应的脚本文件,所述脚本文件中包括所述服务组件的注册脚本,所述注册脚本指示所述服务组件的地址和控制范围;

[0222] 运行所述脚本文件,以对所述目标页面进行加载处理,并基于所述服务组件的地址获取所述服务组件的安装文件;

[0223] 基于所述安装文件部署所述服务组件,并触发所述服务组件对所述控制范围内的页面所关联的业务请求进行监测处理。

[0224] 在一种可能的实现方式中,所述目标页面中包括至少一个候选寄宿程序分别对应的控件,所述处理器901加载并执行存储器904中存放的计算机程序,还用于:

[0225] 响应于针对所述目标页面中所述寄宿程序对应控件的触发操作,从与所述运行环境关联的服务器中获取所述寄宿程序的资源文件,并基于所述资源文件加载所述寄宿程序的页面。

[0226] 在一种可能的实现方式中,所述处理器901加载并执行存储器904中存放的计算机程序,还用于:

[0227] 响应于针对所述目标页面的重新加载请求,再次获取所述脚本文件;

[0228] 运行再次获取到的脚本文件,以对所述目标页面进行重新加载处理,并基于所述服务组件的地址获取所述服务组件的更新安装文件;

[0229] 若所述更新安装文件相较于所述安装文件有更新,则基于所述更新安装文件对所述服务组件进行更新处理。

[0230] 在一种可能的实现方式中,所述处理器901加载并执行存储器904中存放的计算机程序,用于基于所述更新安装文件对所述服务组件进行更新处理,具体用于:

[0231] 基于所述更新安装文件进行安装处理,得到更新服务组件;

[0232] 若检测到所述控制范围内的页面已关闭,则触发所述更新服务组件对所述控制范围内的页面所关联的业务请求进行监测处理。

[0233] 在一种可能的实现方式中,所述处理器901加载并执行存储器904中存放的计算机程序,还用于:

[0234] 若在预设时长范围内未检测到与所述控制范围内的页面关联的业务请求,则停止运行所述服务组件;

[0235] 在停止运行所述服务组件之后,若检测到所述控制范围内的页面中,与所述服务组件的地址同源的新增业务请求,则重新运行所述服务组件,并通过所述服务组件对所述新增业务请求进行拦截处理。

[0236] 在一种可能的实现方式中,所述目标响应头中还包含有解析信息,所述解析信息用于指示预定义响应头;

[0237] 所述处理器901加载并执行存储器904中存放的计算机程序,用于对所述编码响应头进行解码处理,具体用于:

[0238] 访问所述解析信息指示的所述预定义响应头中存储的所述编码响应头;

[0239] 基于预设解码方式对所述编码响应头进行解码处理。

[0240] 在一种可能的实现方式中,所述处理器901加载并执行存储器904中存放的计算机程序,用于基于所述业务响应信息对所述业务请求进行响应处理,具体用于:

[0241] 若基于与所述业务请求关联的业务逻辑确定所述业务请求与所述业务响应信息不匹配,则基于所述业务响应信息进行报错处理。

[0242] 在一种可能的实现方式中,可由处理器901加载并执行存储器904中存放的计算机程序,以实现上述有关另一种业务请求的响应处理方法实施例中的相应步骤;具体的,上述处理器901加载并执行存储器904中存放的计算机程序,用于:

[0243] 获取业务服务器反馈的与业务请求关联的业务响应头和业务响应体;

[0244] 对所述业务响应头进行编码处理,并根据编码处理得到的编码响应头构建目标响应头;

[0245] 将所述业务响应体转换为特定传输格式,得到目标响应体,并根据所述目标响应头和所述目标响应体生成目标响应信息;

[0246] 将所述目标响应信息发送至客户端,以使所述客户端对所述编码响应头进行解码处理,基于所述目标响应体和解码得到的响应头生成针对所述业务请求的业务响应信息。

[0247] 在一种可能的实现方式中,所述处理器901加载并执行存储器904中存放的计算机程序,用于获取业务服务器反馈的与业务请求关联的业务响应头和业务响应体,具体用于:

[0248] 向所述业务请求指示的所述业务服务器发送基于所述业务请求生成的代理业务请求,所述业务请求是所述客户端响应于指定应用程序页面的输入操作生成并发送的;

[0249] 接收所述业务服务器返回的所述业务响应头和所述业务响应体。

[0250] 在一种可能的实现方式中,所述处理器901加载并执行存储器904中存放的计算机程序,用于根据编码处理得到的编码响应头构建目标响应头,具体用于:

[0251] 将所述编码响应头存储在预定义响应头中,并生成用于指示所述客户端访问所述预定义响应头的解析信息;

[0252] 根据所述预定义响应头和所述解析信息,构建所述目标响应头。

[0253] 在一种可能的实现方式中,所述处理器901加载并执行存储器904中存放的计算机程序,用于根据所述预定义响应头和所述解析信息,构建所述目标响应头,具体用于:

[0254] 生成用于指示所述特定传输格式的内容类型信息;

[0255] 根据所述内容类型信息、所述预定义响应头和所述解析信息,构建所述目标响应头。

[0256] 在一种可能的实现方式中,所述处理器901加载并执行存储器904中存放的计算机程序,用于根据所述内容类型信息、所述预定义响应头和所述解析信息,构建所述目标响应头,具体用于:

[0257] 对所述业务响应头中的特定字段进行检查,若检查出所述业务响应头包括所述特定字段,则基于所述特定字段和所述特定字段所对应的值,生成响应属性信息;

[0258] 根据所述响应属性信息、所述内容类型信息、所述预定义响应头,以及所述解析信息,构建所述目标响应头。

[0259] 应当理解,在本申请实施例中,所称处理器901可以是中央处理单元(CentralProcessing Unit,CPU),该处理器901还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application SpecificIntegratedCircuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。

[0260] 本申请实施例中提供一种计算机可读存储介质,上述计算机可读存储介质存储有计算机程序,上述计算机程序包括程序指令,上述程序指令被处理器执行时,可执行上述所有实施例中所执行的步骤。

[0261] 本申请实施例还提供一种计算机程序产品或计算机程序,计算机程序产品或计算机程序包括计算机指令,计算机指令存储在计算机可读存储介质中,计算机指令被计算机设备的处理器执行时,执行上述所有实施例中的方法。

[0262] 本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,上述的程序可存储于一计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,上述的存储介质可为磁碟、光盘、只读存储记忆体(Read-Only Memory,ROM)或随机存储记忆体(Random AccessMemory,RAM)等。

[0263] 以上所揭露的仅为本发明一种较佳实施例而已,当然不能以此来限定本发明之权利范围,本领域普通技术人员可以理解实现上述实施例的全部或部分流程,并依本发明权利要求所作的等同变化,仍属于发明所涵盖的范围。

[0264] 另外特别需要说明的是,当本申请以上实施例运用到具体产品或技术中时,若需要获取用户的数据,则需要获得该用户许可或者同意,且相关数据的收集、使用和处理需要遵守相关国家和地区的相关法律法规和标准。< / script>

Claims

1. A method for handling responses to business requests, characterized in that, include: The system receives target response information returned by the proxy server in response to a business request. The target response information includes a target response header and a target response body. The target response header includes an encoded response header generated by the proxy server encoding the obtained business response header. The target response body is obtained by the proxy server converting the obtained business response body into a specific transmission format. The encoded response header is decoded, and service response information is generated based on the target response body and the decoded response header. The service request is processed based on the service response information.

2. The method according to claim 1, characterized in that, The method further includes: In response to a received input operation for a specified application page, a business request corresponding to the input operation is generated; The service request is sent to the proxy server so that the proxy server can obtain the service response header and the service response body from the service server indicated by the service request.

3. The method according to claim 2, characterized in that, The specified application includes a hosting program that runs in the runtime environment provided by the host program, and the host program also runs service components; sending the business request to the proxy server includes: If a business request associated with the page of the hosting program is detected, the address of the business server contained in the business request is modified to a proxy address that is of the same origin as the address of the service component through the runtime environment; If a service request with an address that originates from the same source as the address of the service component is detected, the service component will intercept the service request and forward the intercepted service request to the proxy server.

4. The method according to claim 3, characterized in that, The method further includes: In response to a loading request for a target page, a script file corresponding to the target page is obtained. The script file includes a registration script for the service component, which indicates the address and control scope of the service component. Run the script file to load the target page and obtain the installation file of the service component based on the address of the service component; The service component is deployed based on the installation file, and the service component is triggered to monitor and process business requests associated with pages within the control scope.

5. The method according to claim 4, characterized in that, The target page includes controls corresponding to at least one candidate hosting program, and the method further includes: In response to a trigger operation on the control corresponding to the hosted program in the target page, the resource file of the hosted program is obtained from the server associated with the runtime environment, and the page of the hosted program is loaded based on the resource file.

6. The method according to claim 4, characterized in that, After triggering the service component to monitor and process business requests associated with pages within the control scope, the method further includes: In response to a reload request for the target page, the script file is retrieved again; Run the script file obtained again to reload the target page and obtain the update installation file of the service component based on the address of the service component; If the updated installation file is updated compared to the original installation file, the service component is updated based on the updated installation file.

7. The method according to claim 6, characterized in that, The process of updating the service components based on the updated installation file includes: The update service component is obtained by performing an installation process based on the update installation file. If it is detected that a page within the control scope has been closed, the update service component is triggered to monitor and process the business requests associated with the page within the control scope.

8. The method according to claim 4, characterized in that, The method further includes: If no business request associated with the page within the control scope is detected within the preset time range, the service component will stop running. After the service component is stopped, if a new business request with the same address as the service component is detected on a page within the control scope, the service component is restarted and the new business request is intercepted and processed through the service component.

9. The method according to claim 1, characterized in that, The target response header also contains parsing information, which is used to indicate a predefined response header; Decoding the encoded response header includes: Access the encoded response header stored in the predefined response header indicated by the parsing information; The encoded response header is decoded based on a preset decoding method.

10. The method according to any one of claims 1-9, characterized in that, The process of responding to the service request based on the service response information includes: If the business logic associated with the business request determines that the business request and the business response information do not match, then error processing is performed based on the business response information.

11. A method for handling responses to business requests, characterized in that, include: Obtain the business response headers and body associated with the business request from the business server; The business response header is encoded, and the target response header is constructed based on the encoded response header obtained from the encoding process; The service response body is converted into a specific transmission format to obtain the target response body, and target response information is generated based on the target response header and the target response body; The target response information is sent to the client so that the client can decode the encoded response header and generate business response information for the business request based on the target response body and the decoded response header.

12. The method according to claim 11, characterized in that, The step of obtaining the business response header and business response body associated with the business request from the business server includes: Send a proxy service request generated based on the service request to the service server indicated by the service request, wherein the service request is generated and sent by the client in response to an input operation on a specified application page; Receive the service response header and the service response body returned by the service server.

13. The method according to claim 11, characterized in that, The step of constructing the target response header based on the encoded response header obtained from the encoding process includes: The encoded response header is stored in a predefined response header, and parsing information is generated to instruct the client to access the predefined response header; The target response header is constructed based on the predefined response header and the parsed information.

14. The method according to claim 13, characterized in that, The step of constructing the target response header based on the predefined response header and the parsed information includes: Generate content type information to indicate the specific transmission format; The target response header is constructed based on the content type information, the predefined response header, and the parsing information.

15. The method according to claim 14, characterized in that, The step of constructing the target response header based on the content type information, the predefined response header, and the parsing information includes: The specific field in the business response header is checked. If the business response header is found to include the specific field, response attribute information is generated based on the specific field and its corresponding value. The target response header is constructed based on the response attribute information, the content type information, the predefined response header, and the parsing information.

16. A response processing apparatus for a business request, characterized in that, include: The receiving unit is used to receive target response information returned by the proxy server in response to the business request. The target response information includes a target response header and a target response body. The target response header includes an encoded response header generated by the proxy server encoding the obtained business response header. The target response body is obtained by the proxy server converting the obtained business response body into a specific transmission format. The processing unit is configured to decode the encoded response header, generate service response information based on the target response body and the decoded response header, and process the service request based on the service response information.

17. A response processing apparatus for a business request, characterized in that, include: The acquisition unit is used to acquire the business response headers and business response bodies associated with the business request, which are returned by the business server. The processing unit is used to encode the service response header and construct the target response header based on the encoded response header obtained from the encoding process. A conversion unit is used to convert the service response body into a specific transmission format to obtain a target response body, and to generate target response information based on the target response header and the target response body; The sending unit is used to send the target response information to the client, so that the client can decode the encoded response header and generate service response information for the service request based on the target response body and the decoded response header.

18. An electronic device, characterized in that, include: One or more processors; A memory for storing one or more computer programs, which, when executed by one or more processors, cause the electronic device to implement the response processing method for a service request as described in any one of claims 1-15.

19. A computer-readable medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the response processing method for the business request as described in any one of claims 1-15.

20. A computer program product, characterized in that, The computer program product includes a computer program stored in a computer-readable storage medium. The processor of the electronic device reads from the computer-readable storage medium and executes the computer program, causing the electronic device to perform the response processing method for the service request according to any one of claims 1-15.