Network request processing method and apparatus, computer device, storage medium, and computer program product
By embedding network middleware in the second application, the appropriate network link is dynamically selected to transmit the mini-program request, which solves the complexity and inflexibility problems of mini-programs in the face of network attacks or abnormal traffic in the existing technology, and achieves efficient traffic routing management and service stability.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2025-08-27
- Publication Date
- 2026-04-02
AI Technical Summary
When faced with network attacks or abnormal traffic, existing mini-programs require code modifications to switch network links, resulting in complexity and inflexibility, and failing to guarantee service availability and stability.
By embedding network middleware in the second application, the link configuration of the first application is obtained and link decision processing is performed to dynamically select the appropriate network link to transmit network requests, thus avoiding modification of the code of the first application.
It enables efficient traffic routing management without modifying the mini-program code, ensuring high availability and stability of services, and providing flexible network link selection capabilities.
Smart Images

Figure CN2025117358_02042026_PF_FP_ABST
Abstract
Description
Method, apparatus, computer device, storage medium and computer program product for processing network request
[0001] Cross-reference to Related Applications
[0002] The present application is based on and claims priority to Chinese Patent Application No. 202411375992.6, filed on September 29, 2024, the entire contents of which are incorporated herein by reference. TECHNICAL FIELD
[0003] The present application relates to the technical field of computers, in particular to a method and apparatus for processing network requests, a computer device, a storage medium and a computer program product. BACKGROUND
[0004] An installation-free application (also referred to as a small program) is an application with small size, fast startup, and no need for download and installation. The running of the installation-free application usually depends on a specific platform, such as a software application (e.g., a mobile APP, a desktop application, etc.) supporting the running of the small program. The specific platform can be referred to as a host program of the small program. The host program can load the code of the small program and execute it in the running environment provided by the host program, so that the small program can normally initiate a network request.
[0005] A network link refers to a physical or logical path connecting two or more network devices (e.g., computer devices, routers, switches, etc.) in a computer network. The network link provides a channel for data transmission, enabling network devices to communicate and exchange data with each other. A small program usually has the function of specifying a network link (default network link) for transmitting network requests of the small program to the requested target device. If the network link needs to be switched due to network attacks or abnormal traffic on the specified network link, the developer of the small program needs to modify the code of the small program. This method of selecting a network link by modifying the code of the small program is complex and not flexible enough, and cannot guarantee the availability and stability of the small program service. SUMMARY
[0006] The embodiments of the present application provide a method and apparatus for processing network requests, a computer device, a storage medium and a computer program product. The network requests of a first application can be intelligently directed to a suitable network link for transmission by means of a network middleware built in a second application, without modifying the code of the first application, so as to realize efficient traffic routing management and ensure the high availability and stability of the first application service.
[0007] The embodiment of the present application provides a network request processing method, the method is executed by a computer device, and the method comprises the following steps: obtaining a first network request initiated by a first application program, the first application program is running in a second application program, and the second application program is built-in with a network middleware; obtaining a link configuration of the first application program, the link configuration comprises transmission configuration information of at least one network link; based on the link configuration of the first application program, calling the network middleware to perform link decision processing on the first network request, and obtaining a link decision result; the link decision result is used for indicating a first network link, the first network link is obtained from the at least one network link, and is used for transmitting the first network request; and transmitting the first network request on the first network link.
[0008] The embodiment of the present application provides a network request processing device, the device comprises: an obtaining unit configured to obtain a first network request initiated by a first application program, the first application program is running in a second application program, and the second application program is built-in with a network middleware; the obtaining unit is also configured to obtain a link configuration of the first application program, the link configuration comprises transmission configuration information of at least one network link; a processing unit is configured to, based on the link configuration of the first application program, call the network middleware to perform link decision processing on the first network request, and obtain a link decision result; the link decision result is used for indicating a first network link, the first network link is obtained from the at least one network link, and is used for transmitting the first network request; and the processing unit is also configured to transmit the first network request on the first network link.
[0009] The embodiment of the present application provides a computer device, comprising a memory and a processor, the memory is connected with the processor, the memory is used for storing a computer program, and the processor is used for calling the computer program, so that the computer device executes the network request processing method in the embodiment of the present application.
[0010] The embodiment of the present application provides a computer readable storage medium, the computer readable storage medium stores a computer program, and the computer program is suitable for being loaded and executed by a processor, so that a computer device with the processor executes the network request processing method in the embodiment of the present application.
[0011] The embodiment of the present application provides a computer program product, the computer program product comprises a computer program, and the computer program is stored in a computer readable storage medium. The processor of a computer device reads and executes the computer program from the computer readable storage medium, so that the computer device executes the network request processing method in the embodiment of the present application.
[0012] In the embodiments of the present application, when the first application program runs in the second application program, the first network request initiated by the first application program and the link configuration of the first application program can be acquired, and the link configuration contains the transmission configuration information of at least one network link. It can be seen that the embodiments of the present application can flexibly pre-configure one or more network links for the first application program, thereby providing a selection basis when selecting a suitable network link for the first network request. In addition, in the embodiments of the present application, the network middleware can be built in the second application program, and based on the link configuration of the first application program, the network middleware can be called to perform link decision processing on the first network request to obtain a link decision result. The link decision result is used to indicate the first network link for transmitting the first network request, which is decided from at least one network link. In this way, the first network request can be transmitted on the first network link according to the indication of the link decision result. In this way, with the help of the network middleware built in the second application program, the embodiments of the present application can dynamically decide the first network link suitable for transmitting the first network request from one or more network links pre-configured for the first application program, thereby realizing flexible selection of network links. This selection method of network links can realize efficient traffic routing management and ensure high availability and stability of the first application program service. BRIEF DESCRIPTION OF DRAWINGS
[0013] FIG. 1 is a schematic diagram of the architecture of a processing system according to an embodiment of the present application;
[0014] FIG. 2 is a flowchart of a network request processing method according to an embodiment of the present application;
[0015] FIG. 3a is a schematic diagram of a network link n console according to an embodiment of the present application;
[0016] FIG. 3b is a schematic diagram of a configuration completion interface according to an embodiment of the present application;
[0017] FIG. 4 is a flowchart of a configuration method according to an embodiment of the present application;
[0018] FIG. 5 is a schematic diagram of the system structure of a second application program according to an embodiment of the present application;
[0019] FIG. 6 is a flowchart of another network request processing method according to an embodiment of the present application;
[0020] FIG. 7 is a schematic diagram of an operation flow of traffic configuration management realized by a network request processing method according to an embodiment of the present application;
[0021] FIG. 8 is a schematic diagram of a traffic switching flow according to an embodiment of the present application;
[0022] FIG. 9 is a schematic diagram of the structure of a network request processing apparatus according to an embodiment of the present application;
[0023] FIG. 10 is a structural schematic diagram of a computer device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0024] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application.
[0025] Please refer to FIG. 1, which is an architectural schematic diagram of a processing system provided by an embodiment of the present application; as shown in FIG. 1, the processing system includes a computer cluster and a server 100; the computer cluster can include computer device 200a, computer device 200b, computer device 200c, …, computer device 200n, wherein there can be a communication connection between each computer device in the computer cluster, for example, there is a communication connection between computer device 200a and computer device 200b, and there is a communication connection between computer device 200a and computer device 200c. Meanwhile, any computer device in the computer cluster can have a communication connection with the server 100, for example, there is a communication connection between computer device 200a and the server 100, so that each computer device in the computer cluster can interact with the server 100 through the communication connection. Wherein, the above-mentioned communication connection is not limited to the connection mode, which can be directly or indirectly connected through wired communication mode, or directly or indirectly connected through wireless communication mode, or through other ways, which are not limited in the present application.
[0026] Wherein, the server 100 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud database, cloud service, cloud computing, cloud function, cloud storage, network service, cloud communication, middleware service, domain name service, security service, content delivery network (CDN), and basic cloud computing services such as big data and artificial intelligence platform. Any computer device in the computer cluster can be a smart phone, a tablet computer, a notebook computer, a desktop computer, a palm computer, a mobile internet device (MID), a wearable device (such as a smart watch, a smart bracelet, etc.), a smart computer, a smart car, etc. Any computer device in the computer cluster can support any operating system, such as a desktop operating system, a server operating system, a mobile operating system, an embedded operating system, etc.
[0027] A second application program can be installed in the computer device, which can be any application program supporting the running of the applet, i.e., the second application program can serve as a host program of the applet to provide a running environment for the applet. Illustratively, the second application program can be an instant messaging application program, a payment application program, a news reading application program, a social application program, a face brushing application program, a check-in application program, etc. installed in the computer device. The first application program can be an applet (i.e., an installation-free application program) running in the second application program. The applet is a small, fast-starting, and installation-free application program. The applet is developed based on a programming language and relies on a host program for running, and is an application form between a traditional web page and a traditional application program.
[0028] In the development of the applet, the developer of the applet can use a request application program interface (API) provided by the applet framework itself to initiate a network request. The request API is an API for initiating a network request, such as wx.request (an API for sending a HyperText Transfer Protocol (HTTP) / HyperText Transfer Protocol Secure (HTTPS) request), WebSocket (an API for implementing a real-time communication function), etc. The applet framework refers to a tool set providing a set of development specifications, basic components, API interfaces, etc., for developing and managing the applet. For example, the developer of the applet can define a configuration object for a certain specific control (or a certain specific operation), which can include request uniform resource locator (URL), request method, request header, request body, etc. The request URL is an address for locating and accessing a network resource. For the applet, the request URL usually includes the following parts: protocol (e.g., HTTP, HTTPS, etc.), domain name (indicating the device where the resource is located, i.e., indicating the target device), resource path (indicating the location of the required resource on the target device), query parameter (the query parameter is an optional parameter for passing additional information to the target device). When the specific control is triggered (or the specific operation is performed), the applet can pass the previously defined configuration object into the request API and call the request API to initiate a network request.
[0029] The applet can obtain the Internet Protocol (IP) address of the target device by performing domain name resolution on the request URL, so that the applet can know that the network request will be sent to the target device through the IP address of the target device. However, the applet itself cannot directly control the network link through which the network request is transmitted, because in a computer network, the path of transmitting data is determined according to the network topology and the routing table. The network topology refers to the connection relationship between various network devices in the computer network. For example, a computer network can include multiple routers and switches, which are connected by links to form a network topology structure. When the applet initiates a network request, the request packet (the network request is encapsulated into a request packet, and the request packet is transmitted in the network in the form of a request packet, and the request packet is a structured data unit) will be transmitted between these network devices according to the network topology, and will pass through multiple network devices to reach the target device. The routing table is a record stored in the network device, which is used to determine the forwarding path of the request packet. For example, when the request packet reaches a network device, the network device will look up the information of the next hop in the routing table according to the IP address of the target device, and then forwards the request packet to the next network device, and the request packet is forwarded hop by hop until it reaches the target device. The network link used to transmit the network request determined by the IP address of the target device is called the specified network link (i.e., the default network link) of the applet. In addition, the non-specified network link can be any network link other than the specified network link, which can be used to transmit the network request to the target device.
[0030] In the process of the applet accessing the target device, flexible selection and switching of network links are often needed according to different network environments and business requirements to cope with various unstable network conditions and transmission pressures. For example, in order to improve the security of the business, in an implementation manner, the network request of the applet can be accessed to a security gateway, the security gateway performs anomaly detection on the network request, and after the applet successfully passes the anomaly detection, the security gateway forwards the network request to the target device through an encrypted transmission channel. Anomaly detection is a detection means for identifying malicious network attacks, abnormal network behaviors or abnormal network traffic, aiming to improve the security of the network system. The security gateway is a network security device that can provide firewall protection, private link, traffic management (such as load balancing, traffic control, etc.), weak network acceleration and other functions. Firewall protection means that the security gateway can detect and control data traffic entering and exiting the network to prevent unauthorized access and network attacks. Private link means that the security gateway can establish a private encrypted transmission channel to protect the privacy and integrity of data during transmission and prevent data tampering. Traffic management means that the security gateway can detect, schedule and control data traffic to achieve data traffic splitting, rate limiting and optimization to ensure reasonable allocation of network resources and balance of traffic load. Weak network acceleration means that the security gateway can improve the speed of data transmission in poor network conditions to improve user experience. Load balancing means a technology that distributes network traffic or workload to multiple servers or other computing resources. Traffic control means limiting traffic of a certain type or magnitude to prevent network congestion or unnecessary resource consumption. In another implementation manner, the network request of the applet can be accessed to a Web application firewall, the Web application firewall performs anomaly detection on the network request, and after the applet successfully passes the anomaly detection, the Web application firewall forwards the network request to the target device. The Web application firewall is a network security tool for protecting applications from various network attacks and threats such as Structured Query Language (SQL) injection, Cross Site Scripting, Cross-site Request Forgery (CSRF), Distributed Denial of Service (DDoS) attacks, etc. For example, in order to improve the response speed of the business, in an implementation manner, the network request of the applet can be accessed to a security gateway, the security gateway performs at least one of the following processing on the network request: traffic management and weak network acceleration, and transmits the network request to the target device. In another implementation manner, the network request of the applet can be accessed to a reverse proxy server, and the reverse proxy server forwards the network request to the target device.The reverse proxy server can provide load balancing, cache resources (such as response data), private links, and the like. For another example, when the network performance of a certain network link is unstable, causing the network request initiated by the applet to fail to be successfully transmitted, the transmission is switched to another network link with normal network performance, such as selecting a new network link for transmission, and then falling back to the specified network link for transmission. Among them, the network performance refers to the efficiency and effectiveness of the network link in the data transmission process. Network performance usually involves multiple aspects, including bandwidth, network delay, packet loss rate, throughput, request success rate, and response time, and the like. The bandwidth refers to the amount of data that the network link can transmit. The larger the bandwidth, the better the network performance. The network delay refers to the time required by the network link in the data transmission process. The lower the network delay, the better the network performance. The packet loss rate refers to the proportion of data lost in the data transmission process of the network link. The lower the packet loss rate, the better the network performance. The throughput refers to the data transmission rate of the network link. The larger the throughput, the better the network performance. The response time refers to the time from receiving a network request to transmitting a response to the network request. The faster the response time, the better the network performance. The request success rate refers to the proportion of successful responses to network requests. The higher the request success rate, the better the network performance. For another example, the network request initiated by the applet can be transmitted on a network link with better network performance among multiple network links.
[0031] Intelligently guiding the network request initiated by the applet to a suitable network link for transmission is one of the focuses of the applet developer in applet development. The technical solutions in the related art include a network access solution based on a traditional software development kit (SDK), a control-based solution, and an interceptor-based network management solution.
[0032] The network access scheme based on the traditional SDK requires integrating the SDK developed by the third-party service platform (such as a security gateway) into the code of the applet, modifying the original request API to the exported function provided by the SDK, and then calling the exported function provided by the SDK to implement network request, data processing and other operations, which can help the applet to successfully access the third-party service platform (such as a security gateway). However, this scheme requires the developer of the applet to manually modify all application programming interfaces related to network requests, and relies on the developer of the applet to update the applet. Moreover, when the network link of the third-party service platform is problematic, it cannot quickly fallback to the specified network link, increasing the operational risk. The control-based scheme controls the original request API before the applet runs by injecting control code into the applet code, which can process or modify the request data packet before the applet sends a network request, to guide the network request to other network links. Although the control-based scheme can reduce some development work, the developer of the applet still needs to modify the code of the applet (such as injecting control code) and complete the release update. Moreover, when there are multiple control codes, the processing order problem also brings additional complexity. In addition, the control-based scheme also cannot easily implement intelligent guidance of network links. The network management scheme based on the interceptor requires the developer of the applet to use a request library that supports interceptors. At the start of the applet, the developer of the applet can add an interceptor through the interceptor function provided by the request library, to modify the request data packet before the network request is sent, to guide the network request to other network links. However, this way has low applicability, and different request libraries have different support for interceptors. The developer of the applet may need to make a lot of code changes to access a specific request library, increasing complexity.
[0033] To solve at least one of the above problems in the related art, embodiments of the present application provide a network request processing scheme based on a middleware mechanism, which can intelligently guide the network request initiated by the applet to be transmitted on a suitable network link without modifying the code of the applet (i.e., code-free). The middleware mechanism is a software architecture pattern that allows reusable components (i.e., network middleware) to be inserted into the request process or response process of a network request, and the network middleware intercepts and modifies the request process or response process of the network request. The following describes the scheme provided by the present application in conjunction with a first application, a second application, and a computer device 200a and a server 100 in a computer cluster in FIG. 1.
[0034] The second application program can be installed in the computer device 200a. The second application program can be built-in with a network middleware. In an implementation, the second application program can include a mini-program base library, and the network middleware can be built-in in the mini-program base library. The mini-program base library is a core library of a mini-program framework, and contains core functions and API interfaces for running the mini-program. The code of the mini-program relies on the mini-program base library to implement functions such as page rendering, event processing, network request, and storage data. Therefore, the mini-program base library also refers to the running environment of the mini-program. Generally, the mini-program base library will be iterated in version with the update of the second application program. The developer of the mini-program needs to make corresponding development and debugging according to the version of the currently used mini-program base library, to ensure the normal running of the mini-program.
[0035] In the embodiments of the present application, the network middleware is built in the applet base library, so that the network middleware can be shared by different applets, and the network middleware can act on all applets running on the applet base library. Integrating the network middleware into the applet base library can reduce the maintenance workload and realize unified management and updating, fault repair, etc., without the need for the developer of the applet to modify and maintain the code of the applet. For example, when the first application runs in the second application, the computer device 200a can obtain any network request (referred to as a first network request) initiated by the first application, and obtain the link configuration of the first application, which contains the transmission configuration information of at least one network link. Illustratively, the server 100 can be a backend server of the second application, and the link configuration of the first application can be stored in the server 100, and the computer device 200a can obtain the link configuration of the first application from the server 100 through the second application. The transmission configuration information of each network link in the link configuration of the first application can be set and managed using a visual interface. For example, if the developer of the first application wants to access the security gateway for the network request initiated by the first application, the visual interface can be used to set whether the traffic of the first application is allowed or denied to access the security gateway, and specify the URL and other transmission configuration information allowed to access the security gateway. The traffic of the first application refers to the amount of data sent and received by the first application during network communication, including the network request initiated by the first application and the received response data, etc. It can be seen that the developer of the first application can define the rules for the first application to access the network link through the transmission configuration information of the network link. Based on the link configuration of the first application, the second application can call the network middleware to perform link decision processing on the first network request, and obtain a link decision result. The link decision result is used to indicate the first network link, which is the network link selected from at least one network link in the link configuration and used to transmit the first network request. For example, if the traffic of the first application is allowed to access the security gateway, and the URL carried in the first network request is the URL allowed to access the security gateway, the selected first network link can be the network link through which the first network request is forwarded by the security gateway. For another example, in the process of link decision, the network middleware obtains that the first network request is allowed to be transmitted on multiple network links, and then the network middleware can select a network link with better network performance (e.g., the network performance is better than a preset performance threshold) as the first network link. The second application transmits the first network request on the first network link according to the indication of the link decision result.
[0036] The network performance here can include at least one of the following: Round-Trip Time (RTT), packet loss, throughput / bandwidth, jitter, connection establishment time, error rate / state code anomaly rate, link stability (stability score). Among them, the round-trip time refers to the time in milliseconds from the sending of the first byte by the client to the receipt of the first byte of the server's response packet; when determining the first network link, a preset performance threshold can be set as an RTT threshold, for example, the RTT threshold can be set to 150 ms, therefore, the network link with an RTT less than 150 ms can be taken as the first network link. The packet loss rate refers to the percentage of lost data packets in the total number of data packets sent per unit time; when determining the first network link, a preset performance threshold can be set as a packet loss rate threshold, for example, the packet loss rate threshold can be set to 0.1%, therefore, the network link with a packet loss rate less than 0.1% can be taken as the first network link. The available bandwidth refers to the maximum number of bytes that can be stably transmitted by the network link per unit time; when determining the first network link, a preset performance threshold can be set as a bandwidth threshold, for example, the bandwidth threshold can be set to 10 Mbps, therefore, the network link with a bandwidth greater than 10 Mbps can be taken as the first network link. The jitter refers to the standard deviation or maximum deviation between consecutive RTT samples; when determining the first network link, a preset performance threshold can be set as a jitter threshold, for example, the jitter threshold can be set to 30 ms, therefore, the network link with a jitter greater than 30 ms can be taken as the first network link. The connection establishment time refers to the time required to complete TCP three-way handshake + TLS handshake; when determining the first network link, a preset performance threshold can be set as a connection time threshold, for example, the connection time threshold can be set to 200 ms, therefore, the network link with a connection establishment time greater than 200 ms can be taken as the first network link. The error rate / state code anomaly rate refers to the proportion of network layer errors; when determining the first network link, a preset performance threshold can be set as an error rate threshold, for example, the error rate threshold can be set to 0.5%, therefore, the network link with an error rate less than 0.5% can be taken as the first network link. The link stability is a comprehensive index, which is usually obtained by weighting the historical sliding window of RTT, packet loss and error rate, and outputs a value of 0 to 100 points as the link stability score. In the embodiments of the present application, when determining the first network link, a preset performance threshold can be set as a stability threshold, for example, the stability threshold can be set to 90, therefore, the link stability of each network link can be calculated, and the network link with a link stability greater than 90 points can be taken as the first network link.
[0037] For example, assume that the RTT of gateway link A is 80 ms, the packet loss rate is 0.05%, the available bandwidth is 20 Mbps, the jitter is 25 ms, the time taken to establish a connection is 150 ms, the error rate is 0.1%, and the link stability is 95 points; and the RTT of network link B is 200 ms, the packet loss rate is 2%, the available bandwidth is 5 Mbps, the jitter is 80 ms, the time taken to establish a connection is 300 ms, the error rate is 1%, and the link stability is 60 points. Then, when making a link decision, the network middleware can take the "RTT < 100 ms, packet loss rate < 0.5%, and link stability > 90" set on the visual interface as a hard condition for passing through a secure gateway, so network link A meets all the conditions and is selected as the first network link.
[0038] As can be seen, in the embodiments of the present application, when the first application initiates a network request, the network middleware built in the second application (mini-program basic library) can be called to dynamically decide a suitable network link according to the link configuration of the first application issued by the server, and transmit the network request on the decided network link. In addition, the network middleware can also more flexibly implement intelligent guidance of the traffic of the first application, for example, when the developer of the first application does not want the network request initiated by the first application to access a secure gateway, the traffic of the first application can be set to refuse to access the secure gateway, at which time the network middleware will not use the secure gateway to transmit the network request of the first application; for another example, the network middleware can select a network link with better network performance to transmit the network request initiated by the first application, and in the case that the network performance of a non-specified network link is poor, the traffic of the first application can also be automatically rolled back to the original specified network link for transmission, ensuring the high availability and stability of the mini-program service. As can be seen, the embodiments of the present application have the ability to integrate traffic control and distribution, can manage and regulate the traffic of the first application in real time, can timely roll back and cut flow when the current network link encounters a problem, and the fault handling mechanism does not depend on the mini-program release and gray mechanism (the so-called gray mechanism refers to gradually releasing a new version or updated function to avoid a fault caused by one-time full deployment), thereby improving the flexibility and controllability of the processing of network requests.
[0039] It can be understood that the above architecture is only an example and does not constitute a limitation on the architecture of the technical solutions provided by the embodiments of the present application. The technical solutions of the present application can also be applied to other architectures. For example, as known by those skilled in the art, with the evolution of architectures and the appearance of new business scenarios, the technical solutions provided by the embodiments of the present application are also applicable to similar technical problems.
[0040] It should be noted that the related data collection and processing in the embodiments of the present application should strictly comply with the requirements of relevant laws and regulations. The acquisition of personal information needs the informed consent of the personal subject (or the legal basis for information acquisition), and the subsequent data use and processing behavior should be carried out within the scope of authorization of laws and regulations and personal information subjects. For example, when the embodiments of the present application are applied to specific products or technologies, such as obtaining the link configuration of the first application, the permission or consent of the author of the target video is required, and the collection, use and processing of related data should comply with relevant laws, regulations and standards in the relevant region.
[0041] Please refer to FIG. 2, which is a flowchart of a network request processing method provided by the embodiments of the present application. The network request processing method involves guiding the network request initiated by the first application to the appropriate network link for transmission. It can be understood that the network request processing method can be executed by a computer device, and the computer device can be any computer device in the computer cluster shown in FIG. 1 (such as computer device 200a). The network request processing method can include the following S101-S104:
[0042] S101, obtaining a first network request initiated by a first application, the first application running in a second application, the second application having a network middleware built-in.
[0043] As described above, the first application can be any applet running in the second application, and the second application can be the host program of the first application. The first network request can be any network request initiated by the first application. The second application can include an applet base library, and the network middleware can be built-in in the applet base library. The network middleware is a component that can intercept and modify the request process or response process of the network request.
[0044] The applet base library also has a request API built-in. In an implementation manner, the first application can call the request API to initiate the first network request. For example, the first application can call the network request API (such as wx.request) to initiate the HTTP request, call the file upload API (such as wx.uploadFile) to initiate the file upload request, call the file download API (such as wx.downloadFile) to initiate the file download request, call the real-time communication API (such as WebSocket) to initiate the real-time communication request, etc. When the first application initiates the first network request, the first network request will pass through the network middleware, that is, the network middleware can be called to obtain the first network request initiated by the first application.
[0045] The first network request can carry request parameters such as a request URL, a request method, a request header, a request body, and the like. By performing domain name resolution on the request URL in the first network request, the IP address of the target device accessed by the first network request can be obtained, and the target device accessed by the first application program can be determined based on the IP address of the target device. The network link used to transmit the first network request based on the IP address of the target device is referred to as a specified network link. In addition, one domain name can correspond to one or more IP addresses. When the domain name in the request URL carried by the first network request corresponds to multiple IP addresses, the number of target devices can be multiple. In this case, a suitable target device can be selected from the multiple target devices to respond to the network request, for example, the first network request is sent to a security gateway or a reverse proxy server, and the security gateway or the reverse proxy server selects a suitable target device from the multiple target devices to respond to the first network request by using a load balancing algorithm. The load balancing algorithm includes, but is not limited to, at least one of the following algorithms: round robin, random selection, weighted round robin, weighted random, minimum connection number, and the like.
[0046] In an embodiment of the present application, the security gateway is a security barrier located between the applet, the Internet, and the business server, and is usually deployed in the form of an independent service or a cluster. The security gateway first performs unified cleaning, authentication, authorization, encryption, and auditing on the traffic entering the applet, and then forwards the clean traffic to the real business server. The functions of the security gateway include, but are not limited to, at least one of the following: unified access, identity and permission, security protection, traffic management, and the like. In link decision, the network middleware identifies that the applet is allowed to access the security gateway through link configuration, and then directs the traffic of the first network request initiated by the network request API (for example, wx.request) to the security gateway domain name or IP. After the security gateway completes the above processing (i.e., unified cleaning, authentication, authorization, encryption, and auditing) of the traffic, the first network request is further forwarded to the business server cluster.
[0047] For the reverse proxy server, it is a normal server from the perspective of the client, but actually the reverse proxy server proxies multiple business servers. The client only communicates with the reverse proxy server, and the reverse proxy server forwards the first network request to one of the business servers according to a load balancing algorithm and returns the response result to the client. The functions of the reverse proxy server include, but are not limited to, at least one of the following: load balancing (such as round robin, weighted round robin, minimum connection number, consistent hashing, etc., to distribute traffic to multiple business servers to avoid single point overload), high availability (such as when a business server is down, the reverse proxy server automatically removes the business server, and the business itself is not aware), cache acceleration (such as caching static resources or hot interfaces to reduce backend pressure), unified entry (such as resolving domain names to the IP of the reverse proxy server to hide the real topology of the backend). In link decision, when the URL of the first network request corresponds to multiple backend IPs (multiple business servers), the network middleware can first send the traffic of the first network request to the reverse proxy server; the reverse proxy server then forwards the first network request to the most suitable business server through a load balancing algorithm, and returns the response result to the applet, which realizes multi-IP routing and hides the details of backend expansion and failure.
[0048] As can be seen, the security gateway is equivalent to an entrance for security check and security management; the reverse proxy server is equivalent to an entrance for load balancing and traffic distribution. The security gateway and the reverse proxy server can be combined in the same gateway cluster, or can be deployed hierarchically: the security gateway implements unified security policy, and the reverse proxy server implements business-level traffic scheduling.
[0049] S102, obtain the link configuration of the first application program, and the link configuration includes transmission configuration information of at least one network link.
[0050] The link configuration of the first application program is configured to guide the network middleware to perform link decision processing based on transmission configuration information of at least one network link, and the link decision processing refers to deciding a network link (as a first network link described below) suitable for transmitting the first network request from the at least one network link. In an implementation manner, the link configuration of the first application program is acquired, including: calling the network middleware to acquire the link configuration of the first application program. The at least one network link can be preconfigured by a developer of the first application program, and the embodiments of the present application do not limit this. For example, the at least one network link can include: a network link for forwarding the network request by a security gateway, a network link for forwarding the network request by a Web application firewall, a network link for forwarding the network request by a reverse proxy server, a network link for directly sending the network request to a target device (i.e., a specified network link), and the like. It can be understood that the at least one network link includes at least a specified network link for transmitting the first network request and other non-specified network links, and when there is no other non-specified network link, the path through which the data transmission defaults to pass is the specified network link. The number of the at least one network link can be N, and any network link in the N network links is represented as a network link n, n and N are positive integers, and n is less than or equal to N. The transmission configuration information of the network link n can include access criteria of the network link n, and the access criteria of the network link n refers to a rule for the first application program to access the network link n, in other words, the access criteria of the network link n defines the specification and requirement for the first application program to use the network link n. In an implementation manner, the transmission configuration information of the network link n and the identifier of the first application program can be stored in association, so as to quickly acquire the transmission configuration information of the network link n based on the identifier of the first application program.
[0051] For example, the access criteria can include one or more of access permission criteria, address access criteria, account access criteria, traffic access criteria, and version access criteria. The access permission criteria, the address access criteria, the account access criteria, the traffic access criteria, and the version access criteria are described in detail below in connection with the network link n. The access permission criteria of the network link n defines whether the first application is allowed to access the network link n. For example, a link switch of the network link n can be set in the visual interface, and when the link switch of the network link n is turned on, it indicates that the first application is allowed to access the network link n. When the link switch of the network link n is turned off, it indicates that the first application is denied to access the network link n. The address access criteria of the network link n defines the network address that allows the first application to access the network link n. For example, if the first application can access a URL (or domain name) including URL1 (or domain name 1), then URL1 (or domain name 1) can be set in the visual interface as the network address that allows the first application to access the network link n. The account access criteria of the network link n defines the account that allows the first application to access the network link n. For example, the account of the developer of the first application can be set in the visual interface as the account that allows the first application to access the network link n. The account of the developer can be an account registered in the second application or an account registered in the first application. The version access criteria of the network link n defines the version category that allows the first application to access the network link n, and the version category of the first application includes but is not limited to: online version, experience version, and development version. The traffic access criteria of the network link n defines the gray traffic that allows the first application to access the network link n, and the gray traffic refers to the traffic that is allowed to access. For example, the traffic access criteria of the network link n includes traffic proportion gray, and the traffic proportion gray is used to indicate the proportion of the gray traffic in the total traffic. For example, if the traffic proportion gray is 5%, only 5% of the traffic (i.e., the gray traffic) will flow through the network link n.
[0052] It can be understood that the developer of the first application can perform gray release of the first application by setting the account access criteria of the network link n, the version access criteria of the network link n, or the traffic access criteria of the network link n. In other words, the network link n is gradually released to a small part of the traffic, and after verification, the range is gradually expanded until the network link n is released to all the traffic. In this way, the risk that may be caused by large-scale release can be effectively reduced, and the opportunity for real-time feedback of the impact of new functions is provided to reduce the risk and ensure system stability. In addition, the developer of the first application can start or disable the network link n by the access permission criteria of the network link n, and the rapid access and rapid disconnection of the network link can be achieved.
[0053] In an implementation, the link configuration of the first application can be stored in a backend server of the second application. In an implementation, a backend service system of the second application can be deployed on the backend server of the second application, and the backend service system can include an application management module. The link configuration of the first application can be stored in the application management module by the backend service system. For example, the application management module can be a mini-program configuration center, which is a functional module for centrally managing various configuration options and parameters of a mini-program. In addition to storing the link configuration of the mini-program, the mini-program configuration center can also store basic information (such as name, icon, style, etc.) of the mini-program, permission control (setting user permissions of the mini-program), and the like.
[0054] In a possible implementation, the link configuration of the first application is obtained by: when the first application is run for the first time in the second application, calling a network middleware to obtain the link configuration of the first application from the application management module based on the identifier of the first application; or the first application has been started in the second application, and the identifier of the first application is associated with a login account in the second application. The identifier (at least including the identifier of the first application) associated with the account can be used to periodically call the network middleware to obtain the link configuration of the first application from the application management module. The network middleware can store the obtained link configuration of the first application locally, so that it is not necessary to pull the link configuration of the first application from the remote application management module in real time, which is beneficial to improve the business response speed.
[0055] The transmission configuration information of the network link n is stored in the application management module by the backend service system. At this time, the backend service system can include a console of the network link n and a configuration platform of the network link n in addition to the application management module. The console of the network link n is a visual interface for managing and configuring the network link n, and the configuration platform of the network link n is a tool for managing and configuring the network link n. The developer of the first application can configure the transmission configuration information of the network link n in the console of the network link n, and send the transmission configuration information of the network link n to the configuration platform of the network link n through the console of the network link n after confirming that the configuration of the transmission configuration information of the network link n is completed. The configuration platform of the network link n can store the transmission configuration information of the network link n locally, and send the transmission configuration information of the network link n to the application management module for storage. For example, the transmission configuration information of the network link n is obtained by calling the network middleware to obtain the transmission configuration information of the network link n from the application management module.
[0056] For ease of understanding, the following takes the network link n as an example, which is a network link forwarding a network request by a security gateway, to introduce the console of the network link n. Please refer to the schematic diagram of the console of the network link n as shown in FIG. 3a. The developer of the first application program can specify the first application program to be configured by inputting the name, application identifier, etc. of the first application program in the input box 31, set whether to open or close the link switch of the network link n through the access switch 32, set the version category allowed to access the network link n by the first application program through the version option 33, set the network address allowed to access the network link n by the first application program through the applet URL configuration bar 34, set the access mode option 35 to set the traffic proportion gray access or full access, and when the traffic proportion gray access is selected, the account allowed to access the network link n can be set in addition to the traffic proportion gray. The developer of the first application program triggers the submission control 36, which means that the transmission configuration information of the network link n is confirmed to be configured, and the console of the network link n sends the transmission configuration information of the network link n to the configuration platform of the network link n. Meanwhile, the console of the network link n can display the configuration completion interface as shown in FIG. 3b.
[0057] If the developer of the first application program wants to access the security gateway, some settings need to be made in the security gateway, for example, the domain name allowed to access (which helps to limit the source of connection and prevent unauthorized domain names from connecting to the security gateway), the IP address corresponding to the domain name (which facilitates the security gateway to correctly send traffic to the target device), and the port number corresponding to the domain name, which is used to identify a specific service on the target device. If the security gateway is launched by a self-service provider, that is, the security gateway and the backend server belong to the same service provider, the backend server can directly issue a configuration to the security gateway. If the security gateway is launched by a third-party service provider, the developer of the first application program needs to configure the security gateway. In addition, if a network request is to be sent to the security gateway, at least the gateway address of the security gateway (such as the domain name of the security gateway) needs to be known. Therefore, in an implementation manner, if the network link n includes the security gateway, the gateway address of the security gateway can also be included in the transmission configuration information of the network link n. When the security gateway is launched by a third-party service provider, the gateway address of the security gateway can be configured by the developer of the first application program. The same processing mode is applied to the Web application firewall and the reverse proxy server.
[0058] Please refer to FIG. 4, which is a flowchart of a configuration method according to an embodiment of the present application. As shown in FIG. 4, the configuration method includes the following steps S201-S204:
[0059] S201, a developer of the first application program configures the transmission configuration information of the network link n in a console of the network link n.
[0060] In the embodiment of the application, the developer can complete the visual configuration in the console of the network link n, thereby realizing the configuration of the transmission configuration information of the network link n. When the visual configuration is performed, identity verification can be performed first, the console first adopts the enterprise instant messaging application scanning code / OAuth2 authorization protocol to pass the identity of the developer to the identity and access management (IAM) service, and it is ensured that only the account or subject or administrator having the highest management permission of the applet can modify the transmission configuration information. After the identity verification is performed, front-end form verification can be performed, and the application identifier filled in the input box 31 in FIG. 3a must conform to the regular of the preset application identifier format; and the access version option 33 allows the version list (pulled from the version management center in real time) that has been released in gray to be selected. After the front-end form verification is completed, linkage verification can be performed, and when the access switch 32 is set to “on” and the access mode 35 selects the access according to the proportion of traffic in gray, the front end can automatically pop up the slide control (0-100%) and the account whitelist input box.
[0061] For example, the applet of the developer A is called “XX shopping”, and the AppID is wx1234567890abcdef. When the transmission configuration information of the network link n is configured, “XX shopping” can be input in the input box 31; the access switch 32 is turned on; the access version is selected as “experience version”; the https: / / api.XXbuy.com / is filled in the applet URL configuration field 34; the gray proportion is set to 10%, and the whitelist is filled with 20 internal test instant messaging accounts; and finally the submission control 36 is clicked.
[0062] In the embodiment of the application, when the transmission configuration information of the network link n is configured, a series of actions originally needing to write JSON / YAML, push to Git, and then manually issue by operation and maintenance are reduced to “visual check + one-key submission”, which greatly reduces the operation difficulty; and real-time verification is performed to prevent format errors and reduce the human failure rate; the differentiated gray capability allows the new network link n to be verified in the controllable traffic first, thereby avoiding the “one-size-fits-all” online to cause the crash of the full-amount applet.
[0063] S202, the console of the network link n uploads the transmission configuration information of the network link n to the configuration platform of the network link n.
[0064] S203, the configuration platform of the network link n issues the transmission configuration information of the network link n to the application management module.
[0065] In an implementation, the configuration platform of the network link n can convert the transmission configuration information of the network link n into the configuration of the applet, and deliver the configuration of the applet to the application management module. The configuration of the applet refers to the configuration information in the configuration format applicable to the applet.
[0066] S204, if the network link n includes a security gateway, a Web application firewall or a reverse proxy server, the configuration platform of the network link n delivers the transmission configuration information of the network link n to the security gateway, the Web application firewall or the reverse proxy server in the network link n.
[0067] In an embodiment, the configuration platform of the network link n can deliver the transmission configuration information of the network link n to the security gateway, the Web application firewall or the reverse proxy server in the network link n through a message queue. The message queue is a communication mechanism for message transmission in a software system. In short, the message queue allows applications to communicate in an asynchronous and distributed environment, so that producers can send messages to the queue, and consumers can receive and process the messages from the queue.
[0068] In an implementation, the configuration platform of the network link n can convert the transmission configuration information of the network link n into the configuration of the gateway, the configuration of the firewall or the configuration of the reverse proxy, and deliver the configuration of the gateway, the configuration of the firewall or the configuration of the reverse proxy to the security gateway, the Web application firewall or the reverse proxy server in the network link n. The configuration of the gateway refers to the configuration information in the configuration format applicable to the security gateway, for example, resolving the domain name allowed to access the security gateway into an IP address, so that the configuration of the gateway includes the correspondence between the domain name and the IP address. The configuration of the firewall refers to the configuration information in the configuration format applicable to the Web application firewall. The configuration of the reverse proxy refers to the configuration information in the configuration format applicable to the reverse proxy server.
[0069] As can be seen, in the embodiment of the application, the developer of the first application program can pre-configure at least one network link for the first application program through an intuitive interface configuration manner, without changing the code of the first application program, thereby improving the convenience of network link configuration, and maintaining the purity and seamless integration of the code of the first application program.
[0070] S103, based on the link configuration of the first application program, calling the network middleware to perform link decision processing on the first network request to obtain a link decision result; the link decision result is used to indicate the first network link, and the first network link is obtained from the at least one network link and is used to transmit the first network request.
[0071] In an implementation, based on the link configuration of the first application, the network middleware is invoked to perform link decision processing on the first network request to obtain a link decision result, including the following steps: first, according to the transmission configuration information of each network link in the link configuration of the first application, the network middleware is invoked to determine the access relationship between each network link and the first network request, the access relationship including an allowed access relationship or a denied access relationship. Then, the first network link is determined for the first network request according to the access relationship, wherein the access relationship between the first network link and the first network request is an allowed access relationship.
[0072] When the network middleware is invoked to determine the access relationship between each network link and the first network request according to the transmission configuration information of each network link in the link configuration of the first application, if the access relationship between the network link n and the first network request is an allowed access relationship, it indicates that the first network request can be transmitted on the network link n; if the access relationship between the network link n and the first network request is a denied access relationship, it indicates that the first network request cannot be transmitted on the network link n.
[0073] When developing the applet, the developer of the applet can add the domain names that the applet needs to access to the domain name whitelist of the applet, so that the applet can normally access the devices corresponding to these domain names. Therefore, for the specified network link used to transmit the first network request, the transmission configuration information can refer to the domain name whitelist of the first application, if the domain name in the request URL carried by the first network request is located in the domain name whitelist of the first application, it indicates that the access relationship between the specified network link and the first network request is an allowed access relationship, otherwise, it indicates that the access relationship between the specified network link and the first network request is a denied access relationship.
[0074] In an implementation, the transmission configuration information of the network link n includes the access criteria of the network link n. According to the transmission configuration information of the network link n, the network middleware is invoked to determine the access relationship between the first network request and the network link n, including: the network middleware is invoked to detect whether the first network request meets the access criteria of the network link n; if the first network request meets the access criteria of the network link n, it is determined that the access relationship between the first network request and the network link n is an allowed access relationship; if the first network request does not meet the access criteria of the network link n, it is determined that the access relationship between the first network request and the network link n is a denied access relationship.
[0075] For example, the access criteria includes one or more of access permission criteria, address access criteria, account access criteria, traffic access criteria, and version access criteria.
[0076] In an implementation, if the access criteria includes the access permission criteria, the network middleware is invoked to determine whether the first application is allowed to access the network link n based on the link switch state of the network link n for the first application. For example, when the developer of the first application turns on the access switch 32 in FIG. 3a, the link switch state is on, and the first application is allowed to access the network link n. When the developer of the first application turns off the access switch 32 in FIG. 3a, the link switch state is off, and the first application is not allowed to access the network link n. If the first application is allowed to access the network link n, the first network request is determined to satisfy the access permission criteria for the network link n. Otherwise, the first network request is determined to not satisfy the access permission criteria for the network link n.
[0077] In an implementation, if the access criteria includes the address access criteria, the network middleware is invoked to determine whether the destination address (i.e., the request URL) carried by the first network request is located in an address whitelist of the first application for the network link n. For example, the address whitelist can include at least one of the domain name and the URL set by the developer of the first application via the applet URL configuration field 34 in FIG. 3a. Note that if a domain name is included in the address whitelist of the network link n, all URLs including the domain name are located in the address whitelist of the network link n. If the destination address carried by the first network request is located in the address whitelist of the first application for the network link n, the first network request is determined to satisfy the address access criteria for the network link n. Otherwise, the first network request is determined to not satisfy the address access criteria for the network link n.
[0078] In an implementation, if the access criteria includes the account access criteria, the network middleware is invoked to determine whether the account associated with the first application is located in an account whitelist of the first application for the network link n. The account associated with the first application can be the account logged in the first application or the account logged in the second application. The account whitelist includes the accounts allowed to access. If the account associated with the first application is located in the account whitelist of the first application for the network link n, the first network request is determined to satisfy the account access criteria for the network link n. Otherwise, the first network request is determined to not satisfy the account access criteria for the network link n.
[0079] In an implementation, if the access criteria includes version access criteria, the network middleware is invoked to detect whether the version category of the first application is in a version whitelist of the first application at the network link n. The version whitelist includes version categories that are allowed to access. For example, the developer of the first application can set the version whitelist through the access version option 33 in FIG. 3a. If the version category of the first application is in the version whitelist of the first application at the network link n, it is confirmed that the first network request meets the version access criteria of the network link n, otherwise, it is confirmed that the first network request does not meet the version access criteria of the network link n.
[0080] In an implementation, if the access criteria includes traffic access criteria, the network middleware is invoked to detect whether the first network request is assigned to a gray traffic, which refers to traffic that is allowed to access. For example, the network middleware can assign the gray traffic according to a set traffic proportion gray, and detect whether the first network request is assigned to the gray traffic. If the first network request is assigned to the gray traffic, it is confirmed that the first network request meets the traffic access criteria of the network link n, otherwise, it is confirmed that the first network request does not meet the traffic access criteria of the network link n.
[0081] In one embodiment, the access criterion comprises an access permission criterion, and the first network request is determined to comply with the access criterion of the network link n when the first network request complies with the access permission criterion of the network link n, otherwise, the first network request does not comply with the access criterion of the network link n. In another embodiment, the access criterion comprises an access permission criterion and an address access criterion, and the first network request is determined to comply with the access criterion of the network link n when the first network request complies with the access permission criterion and the address access criterion of the network link n, otherwise, the first network request does not comply with the access criterion of the network link n. In yet another embodiment, the access criterion comprises an access permission criterion, an address access criterion and an account access criterion, and the first network request is determined to comply with the access criterion of the network link n when the first network request complies with the access permission criterion, the address access criterion and the account access criterion of the network link n, otherwise, the first network request does not comply with the access criterion of the network link n. In yet another embodiment, the access criterion comprises an access permission criterion, an address access criterion, an account access criterion and a version access criterion, and the first network request is determined to comply with the access criterion of the network link n when the first network request complies with the access permission criterion, the address access criterion, the account access criterion and the version access criterion of the network link n, otherwise, the first network request does not comply with the access criterion of the network link n. In yet another embodiment, the access criterion comprises an access permission criterion, an address access criterion, an account access criterion, a version access criterion and a traffic access criterion, and the first network request is determined to comply with the access criterion of the network link n when the first network request complies with the access permission criterion, the address access criterion, the account access criterion, the version access criterion and the traffic access criterion of the network link n, otherwise, the first network request does not comply with the access criterion of the network link n.
[0082] In determining the first network link for the first network request according to the access relationship, the access relationship between the first network link and the first network request is an allowed access relationship.
[0083] In one embodiment, P candidate network links can be obtained according to the access relationship, and the access relationship between any one of the P candidate network links and the first network request is an allowed access relationship; P is a positive integer. If P = 1, it indicates that there is only one candidate network link obtained, and the obtained candidate network link is determined as the first network link. If P > 1, a candidate network link can be randomly selected from the P candidate network links as the first network link, or the P candidate network links can be set with priorities, and the first network link can be determined from the P candidate network links in the order from high to low of the priorities of the P candidate network links. The priority of a network link determines the probability of the network link being determined for transmission, and the higher the priority of a network link, the greater the probability of the network link being determined for transmission, and the lower the priority of a network link, the smaller the probability of the network link being determined for transmission.
[0084] Illustratively, the developer of the first application program can set a priority of each of the P network links, and the priority of the P candidate network links can be determined based on the settings of the developer of the first application program.
[0085] Illustratively, the priority of a network link can be determined by an impact factor of the priority of the network link, and the impact factor of the priority of the network link comprises at least one of: a network performance of the network link, a transmission security of the network link, and a matching degree between the network request and the network link. The network performance of the network link can be determined based on one or more of bandwidth, network delay time, packet loss rate, throughput, request success rate, and response time. For example, a performance weight can be set for each of the bandwidth, the network delay time, the packet loss rate, the throughput, the request success rate, and the response time, and a performance score of the network link in each of the bandwidth, the network delay time, the packet loss rate, the throughput, the request success rate, and the response time can be obtained. The score of the network link in the network performance can be obtained by weighted summation of the performance scores of the network link in the bandwidth, the network delay time, the packet loss rate, the throughput, the request success rate, and the response time, and the corresponding performance weights. The greater the score of the network link in the network performance, the better the network performance of the network link. The transmission security of the network link refers to the security exhibited by the network link in the process of data transmission, which can be evaluated by whether the network link uses encryption technology, whether the network link is configured with a firewall and access control, whether the network link implements identity verification and authorization, and whether the network link provides log monitoring and other security protection measures. For example, each security protection measure can correspond to a score, and the score of the network link in the transmission security can be obtained by accumulating the scores of the security protection measures adopted by the network link. The greater the score of the network link in the transmission security, the better the transmission security of the network link. The matching degree between the network request and the network link reflects whether the network link can effectively meet the needs of the network request. For example, if the domain name in the network request corresponds to multiple IP addresses, the matching degree between the network request and the network link with load balancing capability is greater. In an implementation, the matching degree between the network request and the network link can be determined based on the business scenario in which the network request is initiated. For example, the network request initiated in a payment scenario involves sensitive information, so the matching degree between the network request and the network link with higher transmission security is greater. For another example, the network request initiated in an online game scenario needs to ensure the fluency and response speed of the game, so the matching degree between the network request and the network link with better network performance is greater.
[0086] It can be understood that the better the network performance of the network link, the higher the priority of the network link, the worse the network performance of the network link, the lower the priority of the network link. The better the transmission security of the network link, the higher the priority of the network link, the worse the transmission security of the network link, the lower the priority of the network link. The greater the matching degree between the network request and the network link, the higher the priority of the network link, the smaller the matching degree between the network request and the network link, the lower the priority of the network link. Exemplarily, the priority can be represented as a priority score, and the greater the priority score value, the higher the priority. When only one influencing factor is included, the priority score corresponding to the priority of the network link can be the score obtained by the network link under the influencing factor. When multiple (two or more) influencing factors are included, an influence weight can be set for each influencing factor, the scores obtained by the network link under each influencing factor are obtained, and the weighted score is obtained by weighted summation of the scores obtained by the network link under each influencing factor and the corresponding influence weight. The weighted score is the priority score corresponding to the priority of the network link.
[0087] In the embodiment of the application, after the developer of the first application program preconfigures a plurality of network links for the first application program, the network middleware can select a first network link suitable for transmitting the first network request based on network transmission, transmission security, matching degree, and the like. This flexible selection of network links is conducive to improving data transmission efficiency, ensuring data transmission continuity and stability, optimizing network resource utilization, and improving overall network performance.
[0088] S104, transmitting the first network request on the first network link.
[0089] In an embodiment, the first network request can be transmitted on the first network link according to the indication of the link decision result. In an implementation, the first network link can be determined according to the indication of the link decision result. A first transmission protocol can be selected for the first network link. For example, the first network request can be encapsulated according to an HTTP protocol (a kind of application layer protocol for transmitting hypertext). In other words, a request packet corresponding to the first network request conforms to an HTTP protocol format. However, in a scenario in which communication security and data privacy need to be ensured, a security gateway can be more inclined to use an encryption protocol. Therefore, in order to provide additional security measures, the first network request can be re-encapsulated using HTTPS, so that a request packet corresponding to the first network request conforms to an HTTPS protocol format. HTTPS is a secure HTTP protocol in which a secure sockets layer protocol is added on the basis of HTTP. HTTPS provides a higher level of data protection and security by encrypting and authenticating communication data. For example, in order to optimize transmission efficiency to reduce delay, the first network request can be re-encapsulated using an instant messaging (IM) protocol, so that a request packet corresponding to the first network request conforms to an IM protocol format. The IM protocol is a kind of protocol for implementing real-time communication. The IM protocol can use encryption technology to ensure the security of communication and the confidentiality of data. Then, the first network request can be transmitted on the first network link according to the first transmission protocol. For example, a request packet corresponding to the first network request conforming to the HTTPS protocol format (or the IM protocol format) is sent to the security gateway. The security gateway sends the request packet corresponding to the first network request conforming to the HTTPS protocol format (or the IM protocol format) to the target device after passing the anomaly detection.
[0090] In a feasible embodiment, the first network link can support M transmission protocols, M being a positive integer; for example, the network link forwarding network requests through the security gateway can support the HTTPS protocol, the IM protocol, the Secure Shell (SSH) protocol, the Virtual Private Network (VPN) protocol, and the like. Selecting the first transmission protocol for the first network link can be implemented in the following manner: first, obtaining request response information obtained after respectively transmitting historical network requests on the first network link according to the M transmission protocols; the historical network requests refer to network requests transmitted before the first network request. Then, based on the request response information corresponding to each transmission protocol, analyzing the network performance of the first network link under each transmission protocol. For example, the request response information usually includes a request response code, which can include a request failure status code (indicating that the network request cannot be successfully implemented, which can be caused by request timeout, detection of attack on the request (possibly because of imperfect security measures and injection of attack code)), and if the proportion of the request failure status code in the request response information corresponding to a certain transmission protocol is large (such as greater than a preset proportion threshold), it indicates that the network performance of the first network link under the transmission protocol is abnormal (i.e., the network performance is poor). Finally, any one of the M transmission protocols that makes the network performance of the first network link normal can be selected as the first transmission protocol.
[0091] Please refer to FIG. 5, which is a schematic diagram of the system structure of a second application program provided in an embodiment of the present application; as shown in FIG. 5, the second application program is built-in with a network middleware 501, a link switching component 502, a network component 503, and a request API 504; for example, the second application program can include a small program base library 500, and the network middleware 501, the link switching component 502, the network component 503, and the request API 504 can all be built-in in the small program base library 500; in addition, the actual request in FIG. 5 refers to a request actually sent by the network component 503 to the outside (such as a security gateway, a Web application firewall, a reverse proxy server, and the like). The processing method of the network request provided in the embodiment of the present application will be further described below in combination with the system structure diagram shown in FIG. 5. Please refer to the flowchart of the processing method of the network request shown in FIG. 6, which includes the following steps S301-S303:
[0092] S301, the first application program calls the request API to initiate a first network request, and registers a first callback function for the first network request.
[0093] The first callback function includes a first success callback function and a first failure callback function. When the first network request is successfully responded, the first success callback function is called, and the first success callback function is mainly used for processing response data returned by the first network request being successfully responded, such as parsing, displaying, storing, and the like. When the first network request occurs an error or is not successfully responded, the first failure callback function is called, and the first failure callback function is used for processing the case of the first network request failing, for example, displaying an error prompt, retrying a request, recording an error log, and the like.
[0094] S302, the first network request enters the network middleware, and the network middleware decides the first network link from at least one network link based on the link configuration of the first application program.
[0095] It should be noted that the detailed description of S302 can be referred to S103 in the embodiment of FIG. 2, which will not be repeated here.
[0096] S303, the first network request is transmitted on the first network link according to the first transmission protocol.
[0097] The first application program sets a specified network link for the first network request. In an implementation, if the first network link is the specified network link, the first network request is transmitted on the first network link according to the first transmission protocol. In the implementation, the network component can be called to transmit the first network request to the target device on the first network link according to the first transmission protocol. That is, when the first network link is the specified network link, the network component can be directly used to send the first network request to the target device. At this time, the actual request in FIG. 5 refers to the first network request sent by the network component.
[0098] In another implementation, if the first network link is not the specified network link, the first network request is transmitted on the first network link according to the first transmission protocol. In the implementation, the link switching component can be called to perform encapsulation processing on the first network request based on the encapsulation strategy of the first network link, to obtain an encapsulation request packet, and the network component is called to transmit the encapsulation request packet to the target device on the first network link according to the first transmission protocol. At this time, the actual request in FIG. 5 refers to the encapsulation request packet sent by the network component.
[0099] For example, the encapsulation policy of the first network link can include an address of a network device (e.g., a security gateway, a web application firewall, or a reverse proxy server) in the first network link, so that the network component can send the first network request to the correct network device based on the address of the network device in the encapsulated request packet. For example, the encapsulation policy of the first network link can be negotiated between the first application and the network device in the first network link, e.g., the encapsulation policy of the protocol can involve a security protocol (e.g., the first application can negotiate with the security gateway to determine a first transmission protocol for transmitting the first network request), data encryption (e.g., a key for data encryption, a key for data decryption, etc.), an authentication mechanism (e.g., providing a username and password, a digital certificate, etc.), etc., to ensure the security and correctness of the communication.
[0100] In the following, the first network link includes the first gateway, and the encapsulation policy of the first network link is obtained by negotiation between the first application and the first gateway as an example. Exemplarily, the first gateway can be a security gateway, and can also be a traffic gateway (mainly used for controlling and managing network traffic, including load balancing, traffic limiting, data filtering, etc., such as a reverse proxy server), an application layer gateway (used for checking and filtering data conforming to specific rules, such as a Web application firewall), and the like. In an implementation mode, the link switching component encapsulates the first network request based on the encapsulation policy of the first network link to obtain an encapsulated request packet, and transmits the encapsulated request packet to the target device according to the first transmission protocol on the first network link. The link switching component can encapsulate the first network request based on the encapsulation policy of the first network link to obtain an encapsulated request packet, and the encapsulated request packet includes the gateway address of the first gateway. The encapsulation policy of the first network link can include a security protocol, data encryption, authentication mechanism, and the like obtained by negotiation between the first application and the first gateway. According to the gateway address of the first gateway in the encapsulated request packet, the network component transmits the encapsulated request packet to the first gateway according to the first transmission protocol, and the first gateway transmits the encapsulated request packet to the target device according to the first transmission protocol. Wherein, transmitting the encapsulated request packet according to the first transmission protocol means that the encapsulated request packet needs to conform to the format of the first transmission protocol. It should be noted that the link switching component registers a second callback function for the encapsulated request packet, and generates a callback processing chain based on the first callback function and the second callback function. The callback processing chain is used to indicate the request response logic for the first network request. The request response logic is used to represent the calling sequence between the first callback function and the second callback function in the callback processing chain. For example, the request response logic can be that the second callback function precedes the first callback function in the callback processing chain, so that the second callback function is triggered before the first callback function, that is, the request response logic can be that the second callback function precedes the first callback function, and then when the callback function is called, the second callback function is called before the first callback function.
[0101] In the embodiments of the present application, the first callback function includes a first success callback function and a first failure callback function, and the second callback function includes a second success callback function and a second failure callback function. Since the request response logic is used to represent the calling sequence between the first callback function and the second callback function in the callback processing chain, and the calling sequence is that the second callback function is called before the first callback function, when the encapsulated request packet is successfully responded, the second success callback function can be called by the link switching component, and then the first success callback function is called, and the success response result of the first network request is returned. When the encapsulated request packet fails to respond, the second failure callback function can be called by the link switching component, and then the first failure callback function is called, and the failure response result of the first network request is returned. That is, the method can further include the following steps: in response to the encapsulated request packet being successfully responded, the second success callback function is called by the link switching component, and then the first success callback function is called, and the success response result of the first network request is returned; in response to the encapsulated request packet failing to respond, the second failure callback function is called by the link switching component, and then the first failure callback function is called, and the failure response result of the first network request is returned. When the encapsulated request packet is successfully responded, the second success callback function is called, and the second success callback function is mainly used to process the response data returned after the encapsulated request packet request is successfully responded. When the encapsulated request packet occurs an error or is not successfully responded, the second failure callback function is called, and the second failure callback function is used to process the case that the encapsulated request packet request fails, for example, displaying an error prompt, retrying the request, recording an error log, etc. It can be understood that when the encapsulated request packet request is successful, the link switching component can call the second success callback function, and then call the first success callback function to return the success response result of the first network request; when the encapsulated request packet request fails, the link switching component can call the second failure callback function, and then call the first failure callback function to return the failure response result of the first network request. Through the callback processing chain, it can be ensured that the execution of the final callback is not affected by network fluctuations, and the smoothness and consistency of user experience are guaranteed.
[0102] To better serve the applet business party, the first gateway can include a gateway control component and at least one gateway instance, each gateway instance can be an executor of the first gateway function, and the gateway control component can be responsible for managing the at least one gateway instance, for example, the gateway control component is responsible for uniformly issuing link configurations of the first application to each gateway instance, the gateway control component is responsible for creating or logging out the gateway instance, the gateway control component updates the link configuration stored in each gateway instance, and the like. The at least one gateway instance includes a gateway instance of the first application, for example, the gateway instance can be any shared gateway instance allocated for the first application, or a gateway instance private to the first application, and the gateway address of the first gateway in the encapsulated request packet is the gateway address of the gateway instance. At this time, according to the gateway address of the first gateway in the encapsulated request packet, the network component is called to transmit the encapsulated request packet to the first gateway according to the first transmission protocol, and the first gateway transmits the encapsulated request packet to the target device according to the first transmission protocol. It can be that according to the gateway address of the gateway instance in the encapsulated request packet, the network component is called to transmit the encapsulated request packet to the gateway instance according to the first transmission protocol, and the gateway instance transmits the encapsulated request packet to the target device according to the first transmission protocol and based on the gateway configuration information of the first network link. It should be noted that the transmission configuration information of the first network link is configured in the first configuration interface (i.e., the console of the first network link) provided by the back-end service system of the second application, and is converted into the gateway configuration information of the first network link by the back-end service system. That is, after the transmission configuration information of the first network link is configured in the first configuration interface provided by the back-end service system of the second application, the transmission configuration information of the first network link will be converted into the gateway configuration information of the first network link by the back-end service system, and then the back-end service system can send the gateway configuration information of the first network link to the at least one network instance (including the gateway instance) through the gateway control component. The gateway configuration information of the first network link refers to the configuration information in a configuration format suitable for the first gateway, for example, the gateway configuration information of the first network link includes the domain name, the correspondence relationship between the IP address and the port.
[0103] In a feasible embodiment, after transmitting the first network request on the first network link, if the first network request cannot be successfully transmitted on the first network link (for example, a response message indicating that the request fails is received, the request takes too long, the request is attacked by a network, etc.), a second network link can be selected from the P-1 candidate network links according to the priority of the P-1 candidate network links from high to low, or a network link can be randomly selected from the P-1 candidate network links as the second network link. The P-1 candidate network links are the other candidate network links except the first network link in the P candidate network links. The first network link is switched to the second network link, and the first network request is transmitted on the second network link; for example, the first network request is encapsulated again according to the encapsulation strategy of the second network link, so that the first network request can be transmitted on the second network link.
[0104] As can be seen, in the embodiments of the present application, the network middleware built in the second application can intelligently guide the rapid switching of network traffic between different network links according to the link configuration dynamically issued by the server, realize efficient traffic routing management, and effectively reduce the development cost and maintenance time without additional code modification or re-release by the developer of the applet. The network middleware not only supports remote configuration and dynamic link adjustment, but also has the ability to automatically switch or fallback to other available links in the case of network exception or link congestion, greatly reducing the situation of request failure or response delay caused by poor network performance of the network link, and ensuring the high availability of the system. At the same time, the embodiments of the present application allow gray traffic control and partial network link enablement, effectively improving the flexibility and adaptability of the network link. In general, the embodiments of the present application provide a highly flexible and automated network link switching scheme, which provides an efficient, stable and easy-to-use network optimization solution for the developers of the applet, and helps to improve the overall network performance and user satisfaction of the applet.
[0105] In the following, an exemplary application of the embodiments of the present application in an actual application scenario will be described.
[0106] The embodiment of the present application provides a network request processing method, which quickly switches the network link of the applet through a network middleware, and the flexible switching of the network link can be realized without changing the code or publishing by the developer. The middleware supports intelligent judgment and gray management of the network link, can flexibly control the switching of part of the traffic, and supports the ability of automatically falling back to the default network link. Since the network middleware runs in the applet basic library, the network middleware is responsible for request routing and processing, and therefore the network request processing method provided by the embodiment of the present application is applicable to all applets in the instant messaging application, and the developer does not need to use a specific request mode, and the fast and convenient network link switching can be realized.
[0107] FIG. 7 is an operation flow diagram of realizing traffic configuration management through the network request processing method provided by the embodiment of the present application, as shown in FIG. 7, the traffic configuration management is mainly completed by the operation of the developer on the console 701 (that is, the gateway console), and the roles involved in the traffic configuration management are the console 701, the gateway configuration platform 702, the applet configuration center 703 and the gateway control center 704.
[0108] When the traffic configuration management is performed, referring to FIG. 7, the user logs in the console 701, selects the applet that needs to quickly switch the network link, and selects the corresponding domain name required, confirms the domain name and the configuration, submits the configuration and saves. In the configuration process, the access version of the applet that can be selected, the proportion of accessing the version and the URL prefix list of accessing (see the schematic diagram of the console shown in FIG. 3a) can be configured; the access of the applet to the gateway console 701 is also supported. That is, the original link is switched back. Then, the console uploads the configuration of the user to the gateway configuration platform 702. The gateway configuration platform 702 converts the configuration into the configuration of the applet and the configuration of the gateway, and respectively deploys. For the gateway instance, the configuration platform will distribute the configuration to the gateway control center 704 through the message queue. For the applet, the link configuration will be issued to the applet configuration center 703, and the subsequent applet will pull the specified configuration from the configuration center. In the embodiment of the present application, after the message queue obtains the latest configuration, the configuration is distributed to each gateway instance through the gateway control center 704. The configuration update is incremental, and for the new configuration, the gateway will automatically reload and replace the new link, and automatically refresh the gateway cache according to the update time of the configuration.
[0109] Through the above process, the developer or administrator can flexibly operate the network link of the applet, and distribute the required link configuration in the form of configuration issuance to the applet end and the gateway layer. The applet end will enter the traffic switching process according to the latest configuration.
[0110] In the embodiments of the present application, the traffic switching process is composed of six roles, as shown in FIG. 8, which are respectively a small program network API 801 (i.e. the above-mentioned request API), a network middleware 802, a traffic control center 803, a network component 804, a link switching component 805 and an actual request 806.
[0111] In the embodiments of the present application, a network middleware 802 is used to judge and analyze the network request (which can be the above-mentioned first network request), and complete the encryption process of the network request. The specific implementation process is as follows: first, the user initiates a network request, which can be usually completed by calling the network API (such as wx.request, wx.uploadFile, wx.downloadFile, etc.) of the small program, and registers the success callback function and the failure callback function (i.e. the first callback function) in the parameters. Then, the network request will enter the network middleware 802. The network middleware 802 judges the current network environment by detecting the network state in real time and receiving the configuration information from the traffic control center 803, and decides whether to switch to a better network link. When the network middleware 802 detects that the current network is unstable or has poor performance, or the network request needs to be encrypted and pass through the gateway, the current network request will be cancelled, and the link switching component 805 is notified to complete the quick switching of the request link, and then the network request is reinitiated. At this time, a new callback function (i.e. the second callback function) is re-registered to ensure that the switching process is transparent to the user. If the network state is stable and has good performance, or the traffic control center 803 issues a disconnection configuration, the current network request will not be switched, and will continue to be executed directly through the existing network, reducing unnecessary switching overhead. Then, the network component 804 selects a suitable network link to initiate the actual request 806. The network component 804 can seamlessly interface with different network types (such as WiFi, cellular network) and clients (such as Android, iOS), ensuring the smooth sending of network requests. Finally, after the request result is returned, the link management module is responsible for executing the pre-registered callback function. If network switching occurs during the request process, the link management module will uniformly process the result to ensure that the execution of the final callback function is not affected by network fluctuations, and to ensure the smoothness and consistency of the user experience.
[0112] Through the above-mentioned process and the dynamic detection and decision mechanism of the link management module, quick switching in different network environments is realized, greatly reducing the network request failure or response delay caused by poor network, having high flexibility, being able to intelligently select the best network link according to different network conditions, and improving the overall network performance and user experience of the small program.
[0113] The above describes the method of the embodiments of the present application in detail. In order to better implement the above-mentioned scheme of the embodiments of the present application, correspondingly, the device of the embodiments of the present application is provided below.
[0114] Please refer to FIG. 9, which is a structural schematic diagram of a network request processing apparatus provided in an embodiment of the present application. The network request processing apparatus can be a computer program (including program code) running in a computer device, for example, the network request processing apparatus can be an application software. The network request processing apparatus can be used to execute corresponding steps in the method provided in the embodiments of the present application. The network request processing apparatus comprises the following units: an obtaining unit 701 and a processing unit 702. The obtaining unit 701 is configured to obtain a first network request initiated by a first application program, the first application program running in a second application program, the second application program being built-in with a network middleware. The obtaining unit 701 is further configured to obtain a link configuration of the first application program, the link configuration containing transmission configuration information of at least one network link. The processing unit 702 is configured to call the network middleware to perform link decision processing on the first network request based on the link configuration of the first application program, to obtain a link decision result. The link decision result is used to indicate a first network link, the first network link being decided from the at least one network link and being used to transmit the first network request. The processing unit 702 is further configured to transmit the first network request on the first network link.
[0115] In some embodiments, the processing unit 702 is further configured to call the network middleware to determine an access relationship between each network link in the link configuration of the first application program and the first network request according to the transmission configuration information of the each network link; the access relationship comprises an allowed access relationship or a denied access relationship; determine the first network link for the first network request according to the access relationship; and the access relationship between the first network link and the first network request is the allowed access relationship.
[0116] In some embodiments, the number of the at least one network link is N, any network link in the N network links is denoted as network link n, n and N are both positive integers, and n is less than or equal to N; the processing unit 702 is further configured to, for any network link n in the N network links, call the network middleware to determine an access relationship between the first network request and the network link n according to the transmission configuration information of the network link n; in the case that n is less than N, perform a plus 1 operation on n and assign the value of n+1 to n, and continue to execute the step of determining the access relationship between the first network request and the network link n.
[0117] In some embodiments, the transmission configuration information of the network link n comprises access criteria of the network link n; the processing unit 702 is further configured to invoke the network middleware to detect whether the first network request complies with the access criteria of the network link n; in response to the first network request complying with the access criteria of the network link n, determine that the access relationship between the first network request and the network link n is an allowed access relationship; in response to the first network request not complying with the access criteria of the network link n, determine that the access relationship between the first network request and the network link n is a denied access relationship.
[0118] In some embodiments, the access criteria comprises one or more of access permission criteria, address access criteria, account access criteria, traffic access criteria, version access criteria; the processing unit 702 is further configured to invoke the network middleware to detect whether the first network request complies with one or more of the access permission criteria, the address access criteria, the account access criteria, the traffic access criteria, the version access criteria of the network link n.
[0119] In some embodiments, the processing unit 702 is further configured to, in response to the access criteria comprising the access permission criteria, invoke the network middleware to detect whether the first application is allowed to access the network link n based on a link switch state of the first application on the network link n; in response to the first application being allowed to access the network link n, confirm that the first network request complies with the access permission criteria of the network link n; in response to the first application not being allowed to access the network link n, confirm that the first network request does not comply with the access permission criteria of the network link n.
[0120] In some embodiments, the processing unit 702 is further configured to, in response to the access criteria comprising the address access criteria, invoke the network middleware to detect whether a destination address carried by the first network request is located in an address whitelist of the first application on the network link n; in response to the destination address being located in the address whitelist of the first application on the network link n, confirm that the first network request complies with the address access criteria of the network link n; in response to the destination address not being located in the address whitelist of the first application on the network link n, confirm that the first network request does not comply with the address access criteria of the network link n.
[0121] In some embodiments, the processing unit 702 is further configured to, in response to the access criteria including the account access criterion, invoke the network middleware to detect whether the account associated with the first application is located in an account whitelist of the first application on the network link n; in response to the account associated with the first application being located in the account whitelist of the first application on the network link n, confirm that the first network request meets the account access criterion of the network link n; and in response to the account associated with the first application not being located in the account whitelist of the first application on the network link n, confirm that the first network request does not meet the account access criterion of the network link n.
[0122] In some embodiments, the processing unit 702 is further configured to, in response to the access criteria including the traffic access criterion, invoke the network middleware to detect whether the first network request is assigned to gray traffic; in response to the first network request being assigned to gray traffic, confirm that the first network request meets the traffic access criterion of the network link n; and in response to the first network request not being assigned to gray traffic, confirm that the first network request does not meet the traffic access criterion of the network link n.
[0123] In some embodiments, the processing unit 702 is further configured to, in response to the access criteria including the version access criterion, invoke the network middleware to detect whether the version category of the first application is located in a version whitelist of the first application on the network link n; in response to the version category of the first application being located in the version whitelist of the first application on the network link n, confirm that the first network request meets the version access criterion of the network link n; and in response to the version category of the first application not being located in the version whitelist of the first application on the network link n, confirm that the first network request does not meet the version access criterion of the network link n.
[0124] In some embodiments, the processing unit 702 is further configured to acquire P candidate network links according to the access relationship, wherein the access relationship between any candidate network link and the first network request is an allowed access relationship; P is a positive integer; if P = 1, the acquired candidate network link is determined as the first network link; and if P > 1, the first network link is determined from the P candidate network links according to the order of the priority of the P candidate network links from high to low.
[0125] In some embodiments, the priority of the network link is used to represent the probability that the network link is determined as the first network link; and the influence factor of the priority of the network link includes at least one of the following: network performance of the network link, transmission security of the network link, and matching degree between the network request and the network link.
[0126] In some embodiments, the processing unit 702 is further configured to, after transmitting the first network request on the first network link, in response to being unable to successfully transmit the first network request on the first network link, determine a second network link from P-1 candidate network links in descending order of priority of the P-1 candidate network links; the P-1 candidate network links are the P candidate network links excluding the first network link; switch the first network link to the second network link, and transmit the first network request on the second network link.
[0127] In some embodiments, the processing unit 702 is further configured to select a first transmission protocol for the first network link; and transmit the first network request on the first network link according to the first transmission protocol.
[0128] In some embodiments, the first network link supports M transmission protocols, M being a positive integer; the processing unit 702 is further configured to obtain request response information obtained after transmitting historical network requests on the first network link according to the M transmission protocols respectively; the historical network requests refer to network requests transmitted before the first network request; determine network performance of the first network link under each transmission protocol based on the request response information corresponding to each transmission protocol; and select any transmission protocol that makes the network performance of the first network link normal from the M transmission protocols as the first transmission protocol.
[0129] In some embodiments, the second application program further has a link switching component and a network component built-in; the first application program sets a specified network link for the first network request; the first network request is used to request access to a target device; the processing unit 702 is further configured to, in response to the first network link being the specified network link, call the network component to transmit the first network request to the target device on the first network link according to the first transmission protocol; and in response to the first network link not being the specified network link, call the link switching component to perform encapsulation processing on the first network request based on the encapsulation strategy of the first network link to obtain an encapsulated request packet, and call the network component to transmit the encapsulated request packet to the target device on the first network link according to the first transmission protocol.
[0130] In some embodiments, the first network link comprises a first gateway, and the encapsulation policy of the first network link is obtained by negotiation between the first application and the first gateway; the first application registers a first callback function for the first network request; the processing unit 702 is further configured to invoke the link switching component to encapsulate the first network request according to the encapsulation policy of the first network link to obtain an encapsulated request packet; the encapsulated request packet comprises a gateway address of the first gateway; and the network component is invoked to transmit the encapsulated request packet to the first gateway according to the first transmission protocol based on the gateway address of the first gateway, and the first gateway transmits the encapsulated request packet to the target device according to the first transmission protocol.
[0131] In some embodiments, the first application registers a first callback function for the first network request; the processing unit 702 is further configured to invoke the link switching component to register a second callback function for the encapsulated request packet; a callback processing chain is generated based on the first callback function and the second callback function; the callback processing chain is used to indicate the request response logic for the first network request; and the second callback function is triggered before the first callback function in the callback processing chain.
[0132] In some embodiments, the first callback function comprises a first success callback function and a first failure callback function, and the second callback function comprises a second success callback function and a second failure callback function; the processing unit 702 is further configured to, in response to the encapsulated request packet being successfully responded, invoke the second success callback function through the link switching component, then invoke the first success callback function, and return a success response result of the first network request; and in response to the encapsulated request packet being failed to respond, invoke the second failure callback function through the link switching component, then invoke the first failure callback function, and return a failure response result of the first network request.
[0133] In some embodiments, the first gateway comprises a gateway control component and at least one gateway instance, and the at least one gateway instance comprises a gateway instance of the first application; the gateway address of the first gateway in the encapsulated request packet is a gateway address of the gateway instance; after the transmission configuration information of the first network link is configured in a first configuration interface provided by a back-end service system of the second application, the transmission configuration information of the first network link is converted into gateway configuration information of the first network link by the back-end service system; and the processing unit 702 is further configured to, according to the gateway address of the gateway instance in the encapsulated request packet, invoke the network component to transmit the encapsulated request packet to the gateway instance according to the first transmission protocol, and transmit the encapsulated request packet to the target device by the gateway instance according to the first transmission protocol and based on the gateway configuration information of the first network link; wherein the gateway configuration information of the first network link is sent to the gateway instance by the back-end service system through the gateway control component.
[0134] In some embodiments, the number of the at least one network link is N, any one of the N network links is denoted as network link n, n and N are both positive integers, and n is less than or equal to N; the backend service system comprises an application management module, and the transmission configuration information of the network link n is stored in the application management module by the backend service system of the second application; the obtaining unit 701 is further configured to invoke the network middleware to obtain the transmission configuration information of the network link n from the application management module.
[0135] According to an embodiment of the present application, each unit in the network request processing apparatus shown in FIG. 9 can be combined into one or several other units respectively or all, or some of the units can be further split into a plurality of units with smaller functions to constitute, which can achieve the same operation without affecting the implementation of the technical effects of the embodiments of the present application. The above-mentioned units are divided based on logical functions, and in actual application, the functions of one unit can also be implemented by multiple units, or the functions of multiple units are implemented by one unit. In other embodiments of the present application, the network request processing apparatus can also include other units, and in actual application, these functions can also be assisted by other units to achieve, and can be implemented by multiple units. According to another embodiment of the present application, the network request processing apparatus shown in FIG. 9 and the network request processing method of the embodiments of the present application can be constructed and implemented by running a computer program (including program codes) capable of executing each step involved in the corresponding method shown in FIG. 2, FIG. 4 or FIG. 6 on a general-purpose computer device such as a computer including processing elements and storage elements such as a central processing unit (CPU), a random access memory (RAM), a read-only memory (ROM), etc. The computer program can be recorded on a computer readable recording medium such as a computer readable recording medium, and loaded into the above-mentioned computer device through the computer readable recording medium, and run therein.
[0136] In the embodiments of the present application, when the first application program runs in the second application program, the first network request initiated by the first application program and the link configuration of the first application program can be acquired, and the link configuration contains the transmission configuration information of at least one network link. It can be seen that the embodiments of the present application can flexibly pre-configure one or more network links for the first application program, thereby providing a selection basis when selecting a suitable network link for the first network request. In addition, in the embodiments of the present application, the network middleware can be built in the second application program, and based on the link configuration of the first application program, the network middleware can be called to perform link decision processing on the first network request to obtain a link decision result, and the link decision result is used to indicate the first network link for transmitting the first network request which is decided from the at least one network link. According to the indication of the link decision result, the first network request is transmitted on the first network link. It can be seen that, with the help of the network middleware built in the second application program, the embodiments of the present application can dynamically decide the first network link suitable for transmitting the first network request from the one or more network links pre-configured for the first application program, thereby realizing flexible selection of network links. This selection method of network links can realize efficient traffic routing management and ensure high availability and stability of the first application program service.
[0137] Based on the network request processing method provided in the above embodiments, the embodiments of the present application further provide a computer device for implementing the network request processing method. Please refer to FIG. 10, which is a structural schematic diagram of a computer device provided by the embodiments of the present application. Please refer to FIG. 10, the computer device includes a processor 801, a communication interface 802 and a computer readable storage medium 803. The processor 801, the communication interface 802 and the computer readable storage medium 803 can be connected by a bus or other means. The communication interface 802 is used to receive and send data. The computer readable storage medium 803 can be stored in the memory of the computer device, and the computer readable storage medium 803 is used to store a computer program, the computer program includes program instructions, and the processor 801 is used to execute the computer program stored in the computer readable storage medium 803. The processor 801 (or CPU) is the computing core and control core of the computer device, which is suitable for reading and executing the computer program, and specifically suitable for loading and executing the program instructions to realize the corresponding method process or corresponding function.
[0138] The embodiment of the present application further provides a computer readable storage medium (Memory). The computer readable storage medium is a memory device in a computer device, and is used for storing computer programs and data. It can be understood that the computer readable storage medium herein can include an internal storage medium in the computer device, and of course can include an extended storage medium supported by the computer device. The computer readable storage medium provides a storage space, and the storage space stores a processing system of the computer device. Moreover, the storage space also stores a computer program (including program code) suitable for being loaded and executed by the processor 801. It should be noted that the computer readable storage medium herein can be a high-speed RAM memory, or a non-volatile memory such as at least one disk memory, or at least one computer readable storage medium located away from the aforementioned processor.
[0139] In one embodiment, the computer readable storage medium stores a computer program; the computer program stored in the computer readable storage medium is loaded and executed by the processor 801 to realize corresponding steps in the network request processing method embodiment described above; in a specific implementation, the computer program in the computer readable storage medium is loaded and executed by the processor 801 to perform the following steps: obtaining a first network request initiated by a first application program, the first application program running in a second application program, the second application program being built-in with a network middleware; obtaining a link configuration of the first application program, the link configuration containing transmission configuration information of at least one network link; based on the link configuration of the first application program, calling the network middleware to perform link decision processing on the first network request to obtain a link decision result; the link decision result is used to indicate a first network link, the first network link being obtained from the at least one network link and being used to transmit the first network request; and transmitting the first network request on the first network link.
[0140] Based on the same inventive concept, the computer device provided in the embodiment of the present application has similar principles and beneficial effects to the network request processing method provided in the method embodiment of the present application, and the implementation principles and beneficial effects of the method can be referred to. For brevity, the description is not repeated here.
[0141] In the embodiment of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, and works together with other related parts to achieve a predetermined target, and can be implemented entirely or partially by using software, hardware (such as a processing circuit or a memory) or a combination thereof. Similarly, one processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be a part of an integral module or unit that includes the functions of the module or unit.
[0142] The embodiment of the present application further provides a computer program product, which comprises a computer program stored in a computer readable storage medium. A processor of a computer device reads and executes the computer program from the computer readable storage medium, so that the computer device executes the network request processing method.
[0143] Those skilled in the art can appreciate that the units and algorithm steps of the examples described in combination with the embodiments disclosed in the present application can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are realized by hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0144] In the above embodiments, all or part of the embodiments can be realized by software, hardware, firmware or any combination thereof. When realized by software, all or part of the embodiments can be realized in the form of a computer program product. The computer program product can include a computer program, which can include program instructions. When the computer program is loaded and executed on a computer, all or part of the processes or functions according to the embodiments of the present application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer program can be stored in a computer readable storage medium or transmitted by a computer readable storage medium. The computer program can be transmitted from one website, computer, server or data center to another website, computer, server or data center by wired (for example, coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (for example, infrared, wireless, microwave, etc.) mode. The computer readable storage medium can be any available medium that can be accessed by a computer or an image processing device such as a server, data center, etc. containing one or more available media sets. The available media can be magnetic media (for example, floppy disk, hard disk, magnetic tape), optical media (for example, digital versatile disc (DVD)) or semiconductor media (for example, solid state disk (SSD)) and the like.
[0145] In the present application, the use of singular elements is intended to represent "one or more" rather than "one and only one", unless otherwise specified. In the present application, "at least one" is intended to represent "one or more", and "multiple" is intended to represent "two or more", unless otherwise specified.
[0146] The above description is only specific embodiments of the present application, but the protection scope of the present application is not limited thereto, any person skilled in the art can easily think of changes or replacements within the technical scope disclosed by the present application, which should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A method for processing a network request, the method being performed by a computer device, the method comprising: obtaining a first network request initiated by a first application, the first application running in a second application, the second application being built-in with a network middleware; obtaining a link configuration of the first application, the link configuration containing transmission configuration information of at least one network link; based on the link configuration of the first application, invoking the network middleware to perform link decision processing on the first network request to obtain a link decision result, the link decision result being used to indicate a first network link, the first network link being decided from the at least one network link and being used to transmit the first network request; transmitting the first network request on the first network link.
2. The method of claim 1, wherein, The based on the link configuration of the first application, invoking the network middleware to perform link decision processing on the first network request to obtain a link decision result comprises: according to the transmission configuration information of each network link in the link configuration of the first application, invoking the network middleware to determine an access relationship between each network link and the first network request, the access relationship including an allowed access relationship or a denied access relationship; determining a first network link for the first network request according to the access relationship, the access relationship between the first network link and the first network request being the allowed access relationship.
3. The method of claim 1 or 2, wherein, The number of the at least one network link is N, any network link in the N network links is denoted as network link n, n and N are both positive integers, and n is less than or equal to N; The according to the transmission configuration information of each network link in the link configuration of the first application, invoking the network middleware to determine an access relationship between each network link and the first network request comprises: for any network link n in the N network links, according to the transmission configuration information of the network link n, invoking the network middleware to determine an access relationship between the first network request and the network link n; in a case that n is less than N, performing a plus 1 operation on n and assigning the result to n, and continuing to perform the step of determining the access relationship between the first network request and the network link n.
4. The method of any one of claims 1 to 3, wherein, The transmission configuration information of the network link n contains an access criterion of the network link n; The according to the transmission configuration information of the network link n, invoking the network middleware to determine an access relationship between the first network request and the network link n comprises: invoking the network middleware to detect whether the first network request meets the access criterion of the network link n; in response to the first network request meeting the access criterion of the network link n, determining that the access relationship between the first network request and the network link n is the allowed access relationship; in response to the first network request not meeting the access criterion of the network link n, determining that the access relationship between the first network request and the network link n is the denied access relationship.
5. The method of any one of claims 1 to 4, wherein, The access criteria comprises one or more of an access permission criterion, an address access criterion, an account access criterion, a traffic access criterion, and a version access criterion. The calling the network middleware to detect whether the first network request conforms to the access criteria of the network link n comprises: The calling the network middleware to detect whether the first network request conforms to the access criteria of the network link n comprises:
6. The method of any one of claims 1 to 5, wherein, The calling the network middleware to detect whether the first network request conforms to the access criteria of the network link n comprises: In response to the access criteria comprising the access permission criterion, calling the network middleware to detect, based on a link switch state of the first application in the network link n, whether the first application is allowed to access the network link n; In response to the first application being allowed to access the network link n, confirming that the first network request conforms to the access permission criterion of the network link n; In response to the first application not being allowed to access the network link n, confirming that the first network request does not conform to the access permission criterion of the network link n.
7. The method of any one of claims 1 to 6, wherein, The calling the network middleware to detect whether the first network request conforms to the access criteria of the network link n comprises: In response to the access criteria comprising the address access criterion, calling the network middleware to detect whether a destination address carried by the first network request is located in an address white list of the first application in the network link n; In response to the destination address being located in the address white list of the first application in the network link n, confirming that the first network request conforms to the address access criterion of the network link n; In response to the destination address not being located in the address white list of the first application in the network link n, confirming that the first network request does not conform to the address access criterion of the network link n.
8. The method of any one of claims 1 to 7, wherein, The calling the network middleware to detect whether the first network request conforms to the access criteria of the network link n comprises: In response to the access criteria comprising the account access criterion, calling the network middleware to detect whether an account associated with the first application is located in an account white list of the first application in the network link n; In response to the account associated with the first application being located in the account white list of the first application in the network link n, confirming that the first network request conforms to the account access criterion of the network link n; In response to the account associated with the first application not being in the account whitelist of the first application on the network link n, it is determined that the first network request does not meet the account access criterion of the network link n.
9. The method of any one of claims 1 to 8, wherein, The calling the network middleware to detect whether the first network request meets one or more of the access permission criterion, the address access criterion, the account access criterion, the traffic access criterion, and the version access criterion of the network link n comprises: In response to the access criterion including the traffic access criterion, the network middleware is called to detect whether the first network request is assigned to gray traffic; In response to the first network request being assigned to gray traffic, it is determined that the first network request meets the traffic access criterion of the network link n; In response to the first network request not being assigned to gray traffic, it is determined that the first network request does not meet the traffic access criterion of the network link n.
10. The method of any one of claims 1 to 9, wherein, The calling the network middleware to detect whether the first network request meets one or more of the access permission criterion, the address access criterion, the account access criterion, the traffic access criterion, and the version access criterion of the network link n comprises: In response to the access criterion including the version access criterion, the network middleware is called to detect whether the version category of the first application is in the version whitelist of the first application on the network link n; In response to the version category of the first application being in the version whitelist of the first application on the network link n, it is determined that the first network request meets the version access criterion of the network link n; In response to the version category of the first application not being in the version whitelist of the first application on the network link n, it is determined that the first network request does not meet the version access criterion of the network link n.
11. The method of any one of claims 1 to 10, wherein, The determining the first network link for the first network request according to the access relationship comprises: According to the access relationship, P candidate network links are obtained, and the access relationship between any one of the candidate network links and the first network request is an allowed access relationship; P is a positive integer; If P = 1, the obtained candidate network link is determined as the first network link; If P > 1, the first network link is determined from the P candidate network links in the order of the priority of the P candidate network links from high to low.
12. The method of any one of claims 1 to 11, wherein, The priority of the network link is used to represent the probability that the network link is determined as the first network link; The influence factor of the priority of the network link includes at least one of the following: network performance of the network link, transmission security of the network link, and matching degree between the network request and the network link.
13. The method of any one of claims 1 to 12, wherein, After the first network request is transmitted on the first network link, the method further comprises: determining a second network link from the P-1 candidate network links in an order from high to low of priority of the P-1 candidate network links, in response to the first network request failing to be successfully transmitted on the first network link; the P-1 candidate network links are network links other than the first network link in the P candidate network links; switching the first network link to the second network link, and transmitting the first network request on the second network link.
14. The method of any one of claims 1 to 13, wherein, The transmitting the first network request on the first network link comprises: selecting a first transmission protocol for the first network link; transmitting the first network request on the first network link according to the first transmission protocol.
15. The method of any one of claims 1 to 14, wherein, The first network link supports M transmission protocols, M being a positive integer; The selecting a first transmission protocol for the first network link comprises: obtaining request response information obtained after historical network requests are respectively transmitted on the first network link according to M transmission protocols; the historical network requests refer to network requests transmitted before the first network request; determining network performance of the first network link under each transmission protocol based on the request response information corresponding to each transmission protocol; selecting any transmission protocol that makes the network performance of the first network link normal as the first transmission protocol from the M transmission protocols.
16. The method of any one of claims 1 to 15, wherein, The second application program further comprises a link switching component and a network component; the first application program sets a specified network link for the first network request; The first network request is used to request access to a target device; The transmitting the first network request on the first network link according to the first transmission protocol comprises: in response to the first network link being the specified network link, calling the network component to transmit the first network request to the target device on the first network link according to the first transmission protocol; in response to the first network link not being the specified network link, calling the link switching component to perform encapsulation processing on the first network request based on an encapsulation strategy of the first network link, to obtain an encapsulation request packet, and calling the network component to transmit the encapsulation request packet to the target device on the first network link according to the first transmission protocol.
17. The method of any one of claims 1 to 16, wherein, The first network link comprises a first gateway, and the encapsulation strategy of the first network link is obtained through negotiation between the first application program and the first gateway; The calling the link switching component to perform encapsulation processing on the first network request based on the encapsulation strategy of the first network link, to obtain an encapsulation request packet, and calling the network component to transmit the encapsulation request packet to the target device on the first network link according to the first transmission protocol comprises: calling the link switching component to perform encapsulation processing on the first network request according to the encapsulation strategy of the first network link, to obtain an encapsulation request packet; the encapsulation request packet comprises a gateway address of the first gateway. According to the gateway address of the first gateway in the encapsulation request packet, the network component is invoked to transmit the encapsulation request packet to the first gateway according to the first transmission protocol, and the first gateway transmits the encapsulation request packet to the target device according to the first transmission protocol.
18. The method of any one of claims 1 to 17, wherein, The first application program registers a first callback function for the first network request; the method further comprises: The link switching component is invoked to register a second callback function for the encapsulation request packet; A callback processing chain is generated based on the first callback function and the second callback function; the callback processing chain is used to indicate the request response logic for the first network request; in the callback processing chain, the second callback function is triggered before the first callback function.
19. The method of any one of claims 1 to 18, wherein, The first callback function includes a first success callback function and a first failure callback function, and the second callback function includes a second success callback function and a second failure callback function; the method further comprises: In response to a successful response of the encapsulation request packet, the second success callback function is invoked by the link switching component, and then the first success callback function is invoked, and a successful response result of the first network request is returned; In response to a failed response of the encapsulation request packet, the second failure callback function is invoked by the link switching component, and then the first failure callback function is invoked, and a failed response result of the first network request is returned.
20. The method of any one of claims 1 to 19, wherein, The first gateway includes a gateway control component and at least one gateway instance, and the at least one gateway instance includes a gateway instance of the first application program; the gateway address of the first gateway in the encapsulation request packet is the gateway address of the gateway instance; after the transmission configuration information of the first network link is configured in the first configuration interface provided by the back-end service system of the second application program, the transmission configuration information of the first network link is converted into gateway configuration information of the first network link by the back-end service system; According to the gateway address of the first gateway in the encapsulation request packet, the network component is invoked to transmit the encapsulation request packet to the first gateway according to the first transmission protocol, and the first gateway transmits the encapsulation request packet to the target device according to the first transmission protocol. According to the gateway address of the first gateway in the encapsulation request packet, the network component is invoked to transmit the encapsulation request packet to the first gateway according to the first transmission protocol, and the first gateway transmits the encapsulation request packet to the target device according to the first transmission protocol.
21. The method of any one of claims 1 to 20, wherein, The number of the at least one network link is N, any one of the N network links is denoted as network link n, n and N are positive integers, and n is less than or equal to N; the backend service system comprises an application management module, and the transmission configuration information of the network link n is stored in the application management module by the backend service system of the second application program; The transmission configuration information of the network link n is obtained, comprising: The network middleware is invoked to obtain the transmission configuration information of the network link n from the application management module.
22. A network request processing apparatus, the apparatus comprising: an obtaining unit configured to obtain a first network request initiated by a first application program, the first application program running in a second application program, and the second application program being built-in with a network middleware; the obtaining unit is further configured to obtain link configuration of the first application program, the link configuration containing transmission configuration information of at least one network link; a processing unit configured to invoke the network middleware to perform link decision processing on the first network request based on the link configuration of the first application program, to obtain a link decision result; the link decision result is used to indicate a first network link, the first network link being decided from the at least one network link and being used to transmit the first network request; the processing unit is further configured to transmit the first network request on the first network link.
23. A computer device, comprising a memory and a processor; the memory is connected with the processor, the memory is used to store a computer program, and the processor is used to invoke the computer program, so that the computer device executes the network request processing method in any one of claims 1 to 21.
24. A computer readable storage medium, the computer readable storage medium storing a computer program, the computer program being adapted to be loaded and executed by a processor, so that a computer device with the processor executes the network request processing method in any one of claims 1 to 21.
25. A computer program product, comprising a computer program, the computer program being stored in a computer readable storage medium, and a processor of a computer device reading and executing the computer program from the computer readable storage medium, so that the computer device implements the network request processing method in any one of claims 1 to 21.
Citation Information
Patent Citations
Request processing method, device, equipment and storage medium
CN113900731A
Multi-link transmission method and device, computer readable storage medium and terminal equipment
CN113993178A
Method and device for communication between applet and host program
CN114003412A
Lightweight communication middleware based on heterogeneous network
CN115720236A
Network resource processing method and system, electronic equipment and storage medium
CN117896209A