H5 request header processing method and device, electronic equipment and readable medium

By processing H5 request headers with a method that filters and manages Cookies based on validated URLs and root domain writes, the method addresses the issue of oversized headers, enhancing reliability and efficiency in H5 page loading.

CN119629239APending Publication Date: 2025-03-14BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311191303.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-09-14
Publication Date
2025-03-14

AI Technical Summary

Technical Problem

The increasing demand for H5 business on terminals leads to larger Cookie sizes in request headers, causing request failures and page loading issues due to oversized request headers.

Method used

A method to process H5 request headers by parsing requests, loading validated URLs with hook code, identifying Cookies written to the root domain, and creating a filter list based on Cookie differences to manage and clean Cookies, ensuring they fit within size limits, thereby reducing the likelihood of request failures and enhancing page loading reliability.

Benefits of technology

This approach effectively reduces the size of H5 request headers, improving access efficiency and reliability by selectively retaining only necessary Cookies, thus preventing page failures and enhancing user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119629239A_ABST
    Figure CN119629239A_ABST
Patent Text Reader

Abstract

The invention provides an H5 request header processing method and device, electronic equipment and a readable medium, and the H5 request header processing method comprises the steps: responding to a request for accessing an H5 page, and analyzing the request to determine a URL; loading the URL passing the preset URL standard verification, and injecting a hook code; determining a Cookie which is written into the root domain name based on JavaScript monitored on the basis of the hook code, and recording the Cookie as a first Cookie; when it is detected that the H5 page is exited, determining a Cookie under the root domain name, and recording the Cookie as a second Cookie; and determining a cleaning list for screening the Cookies according to the first Cookie and the second Cookie. Through the embodiment of the invention, simplification processing of the request header of the H5 page is realized, the probability of page access failure caused by overlarge request header is reduced, and the access efficiency and reliability of the H5 page are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0002] At present, with the continuous upgrading of terminal hardware and the development of various preloading and pre-rendering technologies, the proportion of H5 business in terminal applications is increasing.

[0003] In the related art, there is usually only one root domain name for all H5 services in an App, which will result in many services being under the same root domain name.

[0004] However, as business needs grow, the number of cookies written to the root domain name continues to increase, and cookies are an important part of the request header, which eventually causes the request header to be too large, and the request is rejected, resulting in abnormal problems such as a white screen.

[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention

[0006] The purpose of the present disclosure is to provide a method, device, electronic device and readable medium for processing an H5 request header, which are used to overcome the problem of poor reliability of accessing pages due to limitations and defects of related technologies to at least a certain extent.

[0007] According to a first aspect of an embodiment of the present disclosure, a method for processing an H5 request header is provided, comprising: in response to a request to access an H5 page, parsing the request to determine a URL; loading a URL that passes a preset URL standard check, and injecting a hook code; determining a cookie written to a root domain name based on JavaScript monitored by the hook code, and recording it as a first cookie; determining a cookie under the root domain name when an exit from the H5 page is detected, and recording it as a second cookie; and determining a cleanup list for filtering cookies based on the first cookie and the second cookie.

[0008] In an exemplary embodiment of the present disclosure, determining a cleanup list for filtering cookies according to the first Cookie and the second Cookie includes:

[0009] Calculate the cookie difference between the first cookie and the second cookie;

[0010] Associating the cookie difference with the URL of the currently visited page;

[0011] Parsing the Cookie difference according to the business processing scenario of the URL of the currently visited page;

[0012] Determine the cleanup list according to the analysis result, wherein the cleanup list includes a blacklist and / or a whitelist;

[0013] Set a limit range for cookie size based on the cleanup list.

[0014] In an exemplary embodiment of the present disclosure, determining the cleanup list according to the parsing result includes:

[0015] According to the analysis result, it is determined that the business processing scenario is at least one of the PIN for login, interface anti-theft and screen swiping prevention, and the whitelist is determined according to the Cookie corresponding to the Cookie difference.

[0016] In an exemplary embodiment of the present disclosure, determining the cleanup list according to the parsing result includes:

[0017] According to the analysis result, it is determined that the business processing scenario is at least one of data storage, cross-domain and embedding point, and the blacklist is determined according to the Cookie corresponding to the Cookie difference.

[0018] In an exemplary embodiment of the present disclosure, it further includes:

[0019] After detecting that the application is started, determining whether the cookie in the request header for accessing the H5 page meets the cookie size limit range;

[0020] If the Cookie in the request header for accessing the H5 page is determined, only the key value of the Cookie that hits the whitelist is retained, and / or the key value of the Cookie that hits the blacklist is deleted.

[0021] In an exemplary embodiment of the present disclosure, it further includes:

[0022] When detecting the request header of the H5 page accessing the network interface, if the HTTP error or exception code is 400 or 431, only the key value of the cookie hit by the whitelist is retained, and / or the key value of the cookie hit by the blacklist is deleted.

[0023] In an exemplary embodiment of the present disclosure, it further includes:

[0024] Build a JavaScript bridge between the local storage of the H5 page and the native local storage;

[0025] Based on the JavaScript bridge, the local storage data of the H5 page is converted into native local storage data;

[0026] Clean and / or monitor the stored data through the preset native call function.

[0027] In an exemplary embodiment of the present disclosure, it further includes:

[0028] The URL without the query parameter is concatenated with the timestamp when any interface is called, and the concatenated result is determined as the key of the local storage data of the native;

[0029] Determine the value of the local storage data of the H5 page as the value of the local storage data of the native;

[0030] The native local storage data is stored according to the key of the native local storage data and the value of the native local storage data.

[0031] In an exemplary embodiment of the present disclosure, the JavaScript bridge includes at least one of adding or modifying a JavaScript bridge, deleting a JavaScript bridge, and querying a JavaScript bridge.

[0032] In an exemplary embodiment of the present disclosure, cleaning and / or monitoring stored data by using a preset native call function includes:

[0033] The preset clear function is called to clean up the local storage data of the H5 page.

[0034] In an exemplary embodiment of the present disclosure, cleaning and / or monitoring stored data by using a preset native call function includes:

[0035] When it is detected that the storage amount of the native local storage data exceeds the preset storage amount, the LRU function is called to clean up the native local storage data.

[0036] In an exemplary embodiment of the present disclosure, when it is detected that the storage amount of the native local storage data exceeds a preset storage amount, calling the LRU function to clean up the native local storage data includes:

[0037] When it is detected that the storage amount of the native local storage data exceeds the preset storage amount, obtaining the key of the native local storage data through the LRU function;

[0038] Parsing the timestamp contained in the key of the native local storage data;

[0039] The native local storage data is cleaned up according to the timestamp.

[0040] In an exemplary embodiment of the present disclosure, cleaning and / or monitoring stored data by using a preset native call function includes:

[0041] When it is detected that the page is switched to the H5 page, the JavaScript bridge is queried to monitor whether the key of the URL of the currently visited page exists in the local storage data of the native.

[0042] According to a second aspect of an embodiment of the present disclosure, a device for processing an H5 request header is provided, including:

[0043] A parsing module, configured to respond to a request to access an H5 page and parse the request to determine a URL;

[0044] Load the module, set it to load the URL that passes the preset URL standard validation, and inject the hook code;

[0045] A determination module, configured to determine a cookie written into a root domain name based on the JavaScript monitored by the hook code, and record it as a first cookie;

[0046] The determination module is configured to determine the cookie under the root domain name when the exit from the H5 page is detected, and record it as the second cookie;

[0047] The determination module is configured to determine a cleanup list for filtering cookies based on the first Cookie and the second Cookie.

[0048] According to a third aspect of the present disclosure, there is provided an electronic device, comprising: a memory; and a processor coupled to the memory, wherein the processor is configured to execute any one of the methods described above based on instructions stored in the memory.

[0049] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, on which a program is stored, and when the program is executed by a processor, the method for processing the H5 request header as described in any one of the above items is implemented.

[0050] The disclosed embodiment responds to a request to access an H5 page, parses the request to determine the URL, loads the URL verified by a preset URL standard, and injects the hook code. In addition, the cookie written to the root domain name based on the JavaScript monitored by the hook code is determined and recorded as the first cookie. When the exit of the H5 page is detected, the cookie under the root domain name is determined and recorded as the second cookie. Then, a cleanup list for filtering cookies is determined based on the first cookie and the second cookie, thereby achieving a streamlined processing of the request header of the H5 page, reducing the probability of failure to access the page due to an excessively large request header, and improving the access efficiency and reliability of the H5 page.

[0051] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. Obviously, the accompanying drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without creative work.

[0053] Figure 1 A schematic diagram showing an exemplary system architecture to which the H5 request header processing solution of an embodiment of the present invention can be applied;

[0054] Figure 2 is a flowchart of a method for processing an H5 request header in an exemplary embodiment of the present disclosure;

[0055] Figure 3 is a flowchart of another method for processing an H5 request header in an exemplary embodiment of the present disclosure;

[0056] Figure 4 is a flowchart of another method for processing an H5 request header in an exemplary embodiment of the present disclosure;

[0057] Figure 5 is a flowchart of another method for processing an H5 request header in an exemplary embodiment of the present disclosure;

[0058] Figure 6 is a flowchart of another method for processing an H5 request header in an exemplary embodiment of the present disclosure;

[0059] Figure 7 is a flowchart of another method for processing an H5 request header in an exemplary embodiment of the present disclosure;

[0060] Figure 8 is a flowchart of another method for processing an H5 request header in an exemplary embodiment of the present disclosure;

[0061] Fig. 9 is a flowchart of another method for processing an H5 request header in an exemplary embodiment of the present disclosure;

[0062] Fig.10 is a flowchart of another method for processing an H5 request header in an exemplary embodiment of the present disclosure;

[0063] Fig.11 is a flowchart of another method for processing an H5 request header in an exemplary embodiment of the present disclosure;

[0064] Fig.12 is a flowchart of another method for processing an H5 request header in an exemplary embodiment of the present disclosure;

[0065] Fig.13 is a flowchart of another method for processing an H5 request header in an exemplary embodiment of the present disclosure;

[0066] Fig.14 It is an interactive schematic diagram of a processing solution for an H5 request header in an exemplary embodiment of the present disclosure;

[0067] Fig.15 It is an interactive schematic diagram of another H5 request header processing solution in an exemplary embodiment of the present disclosure;

[0068] Fig.16 It is an interactive schematic diagram of another H5 request header processing solution in an exemplary embodiment of the present disclosure;

[0069] Fig.17 is a block diagram of a device for processing an H5 request header in an exemplary embodiment of the present disclosure;

[0070] Fig.18 is a block diagram of an electronic device in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION

[0071] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present disclosure will be more comprehensive and complete, and the concepts of the example embodiments are fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present disclosure.

[0072] In addition, the accompanying drawings are only schematic diagrams of the present disclosure, and the same reference numerals in the drawings represent the same or similar parts, so their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities, which do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.

[0073] Figure 1 A schematic diagram of an exemplary system architecture to which the H5 request header processing solution of an embodiment of the present invention can be applied is shown.

[0074] like Figure 1 As shown, the system architecture 100 may include one or more of terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.

[0075] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. According to the implementation requirements, there may be any number of terminal devices, networks and servers. For example, the server 105 may be a server cluster composed of multiple servers.

[0076] The client can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Terminal devices 101, 102, 103 can be various electronic devices with display screens, including but not limited to smart phones, tablet computers, portable computers, desktop computers, etc.

[0077] In some embodiments, the H5 request header processing method provided in the embodiments of the present invention is generally executed by the server 105. Accordingly, the H5 request header processing device is generally set in the terminal device 103 (or the terminal device 101 or 102). In other embodiments, some terminals may have functions similar to those of the server device to execute the present method.

[0078] The exemplary embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.

[0079] Figure 2 It is a flowchart of a method for processing an H5 request header in an exemplary embodiment of the present disclosure.

[0080] refer to Figure 2 , the processing methods of H5 request header may include:

[0081] Step S202, in response to a request to access an H5 page, the request is parsed to determine a URL (Uniform Resource Locator).

[0082] In an exemplary embodiment of the present disclosure, an App is opened to access an H5 page, and when WebView is initialized, the Cookie under the root domain name is obtained and the data is saved.

[0083] Step S204, loading the URL verified by the preset URL standard and injecting the hook code.

[0084] In an exemplary embodiment of the present disclosure, a URL is loaded and the hook js document.Cookie code is injected, and the content of the Cookie written by the monitored JS through the document.Cookie method is reported. Here, it is necessary to determine whether the Cookie written by JS is written under the root domain name. If it is only written under the second-level or third-level domain name, no processing is performed. If it is written under the root domain name, the content, size and current page URL of the Cookie are reported to the monitoring platform. When the page exits, the Cookie under the root domain name is obtained again, and the difference is compared with the Cookie in the WebView initialization phase and the difference is reported to the monitoring platform. Through this difference, it can be basically determined which Cookies are written under the root domain name on the current H5 page, and it serves as an important reference data for subsequent governance.

[0085] Step S206, determine the Cookie written into the root domain name based on the JavaScript monitored by the hook code, and record it as the first Cookie.

[0086] Step S208, when the exit of the H5 page is detected, the Cookie under the root domain name is determined and recorded as the second Cookie.

[0087] Step S210, determining a cleanup list for filtering cookies according to the first Cookie and the second Cookie.

[0088] The disclosed embodiment responds to a request to access an H5 page, parses the request to determine the URL, loads the URL verified by a preset URL standard, and injects the hook code. In addition, the cookie written to the root domain name based on the JavaScript monitored by the hook code is determined and recorded as the first cookie. When the exit of the H5 page is detected, the cookie under the root domain name is determined and recorded as the second cookie. Then, a cleanup list for filtering cookies is determined based on the first cookie and the second cookie, thereby achieving a streamlined processing of the request header of the H5 page, reducing the probability of failure to access the page due to an excessively large request header, and improving the access efficiency and reliability of the H5 page.

[0089] In an exemplary embodiment of the present disclosure, the preset URL standards may include the following:

[0090] 1) The URL cannot contain spaces, line breaks, Chinese characters, and other special characters. Special characters need to be encoded.

[0091] 2) The URL capitalization must be consistent. If the capitalization of the same URL is inconsistent, the browser will consider it as a different URL.

[0092] 3) The URL cannot carry any client or device sensitive information in plain text.

[0093] 4) The data interface uses POST requests when it is not necessary to reduce the size of the request header and improve request security.

[0094] 5) The URL must not repeatedly carry User-Agent, Cookie, or other information that is already fixed in other headers, such as system version, model, etc.

[0095] 6) The length of the HTML cross-app sharing URL must be less than 1k, and the length of the in-app redirect URL must be less than 600 bytes.

[0096] 7) The URL length of resource requests such as JS, CSS, and images must be less than 300 bytes.

[0097] 8) The length of the interface GET request URL must be less than 1k.

[0098] 9) The length of the interface POST request URL must be less than 500 bytes.

[0099] The following is a detailed description of each step of the H5 request header processing method.

[0100] In an exemplary embodiment of the present disclosure, Figure 3 As shown, the cleaning list for filtering cookies determined according to the first Cookie and the second Cookie includes:

[0101] Step S302, calculating the Cookie difference between the first Cookie and the second Cookie.

[0102] Step S304, associating the Cookie difference with the URL of the currently visited page.

[0103] Step S306: parsing the Cookie difference value according to the business processing scenario of the URL of the currently visited page.

[0104] Step S308: determining the cleanup list according to the analysis result, wherein the cleanup list includes a blacklist and / or a whitelist.

[0105] Step S310, setting a limit range of Cookie size according to the cleanup list.

[0106] In an exemplary embodiment of the present disclosure, the normal startup stage of the Android program is: onCreate()->onStart()->onResume(); the normal exit stage is: onPause()->onStop()->onDestory(). In the onResume() stage, the H5 page has not been loaded yet. At this time, a String value is used to record the Cookie value (assuming it is String a) under the root domain name (for example, jd.com). Then in the onPause() stage, another String value is used to record the Cookie value at this time (assuming it is String b), and the difference between a and b is compared. The difference part represents the Cookie written by the current page under the root domain name. The difference and the URL of the night page are reported, and the Cookie difference corresponding to the URL is subsequently analyzed. Based on the Cookie difference, the source of the Cookie write can be analyzed, and the relevant business is promoted to be rectified, and finally a blacklist and a whitelist are formulated.

[0107] In an exemplary embodiment of the present disclosure, the upper limit of the size of Cookie, as well as the Cookie blacklist and whitelist are configured on the configuration platform. After the App is started, the request interface obtains the Cookie related information configured on the configuration platform. At the same time, the size of Cookie under the root domain name is obtained and compared with the upper limit value. If it exceeds the size index, the key value under the whitelist is retained and the remaining part is cleared. If the whitelist is not configured, it is cleared according to the key value of the blacklist, that is, the priority of the whitelist is greater than that of the blacklist.

[0108] In an exemplary embodiment of the present disclosure, Figure 4 As shown, determining the cleanup list according to the analysis result includes:

[0109] Step S402, according to the analysis result, determine that the business processing scenario is at least one of the PIN for login, interface anti-theft and screen prevention, and then determine the whitelist according to the Cookie corresponding to the Cookie difference.

[0110] In an exemplary embodiment of the present disclosure, Figure 5 As shown, determining the cleanup list according to the analysis result includes:

[0111] Step S502: Determine, based on the analysis result, that the business processing scenario is at least one of data storage, cross-domain, and embedding, and then determine the blacklist based on the Cookie corresponding to the Cookie difference.

[0112] In an exemplary embodiment of the present disclosure, the difference between the reported URL link and the Cookie is analyzed, and only a few logics that must be implemented by writing Cookies are allowed to be written to the root domain name (such as login pin, interface anti-theft, anti-brushing, etc.), and the rest are prohibited from being written (such as data storage, cross-domain, embedding, etc.).

[0113] In an exemplary embodiment of the present disclosure, Figure 6 As shown, it also includes:

[0114] Step S602, after detecting that the application is started, determine whether the Cookie in the request header for accessing the H5 page meets the limit range of the Cookie size.

[0115] Step S604: If it is determined that the Cookie in the request header of the H5 page is accessed, only the key value of the Cookie that hits the whitelist is retained, and / or the key value of the Cookie that hits the blacklist is deleted.

[0116] In an exemplary embodiment of the present disclosure, the priority of the whitelist is higher than that of the blacklist, and both are configurable. If a whitelist exists, the blacklist is ignored, the whitelist data is retained, and the rest of the content is cleared. If the whitelist is empty, the blacklist content is cleared. For example:

[0117] In an exemplary embodiment of the present disclosure, whitelist data: a=1, b=2. Blacklist data: c=3, d=4. Cookie data: a=1, b=2, c=3, d=4, e=5. The final data of the cookie cleaning logic is: a=1, b=2.

[0118] In an exemplary embodiment of the present disclosure, whitelist data: not configured, that is, the data is empty. Blacklist data: c=3, d=4. Cookie data: a=1, b=2, c=3, d=4, e=5. The final data of the cookie cleaning logic is: a=1, b=2, e=5.

[0119] In an exemplary embodiment of the present disclosure, Figure 7 As shown, it also includes:

[0120] Step S702, when detecting the request header of the H5 page accessing the network interface, if the HTTP error or exception code is monitored as 400 or 431, only the key values ​​of the cookies hit by the whitelist are retained, and / or the key values ​​of the cookies hit by the blacklist are deleted.

[0121] In an exemplary embodiment of the present disclosure, when an Http Error exception is monitored and the exception code is 400 or 431, the size and specific content of the header are reported, and Cookies are cleaned up according to the blacklist and whitelist.

[0122] In an exemplary embodiment of the present disclosure, Figure 8 As shown, it also includes:

[0123] Step S802, building a JavaScript bridge between the local storage of the H5 page and the native local storage.

[0124] Step S804: Convert the local storage data of the H5 page into native local storage data based on the JavaScript bridge.

[0125] Step S806: clean up and / or monitor the stored data through a preset native calling function.

[0126] In an exemplary embodiment of the present disclosure, H5 uses the capability of JS Bridge to achieve two-way communication between H5 and Native, thereby replacing H5's local storage with Native local storage. At the same time, further expansion and improvement are made in many aspects such as storage function and storage size limit, and the registered interface name is "NativeStorage".

[0127] In an exemplary embodiment of the present disclosure, Fig. 9 As shown, it also includes:

[0128] Step S902: concatenate the URL without the query parameter with the timestamp of calling any interface, and determine the concatenation result as the key of the native local storage data.

[0129] Step S904: determine the value of the local storage data of the H5 page as the value of the local storage data of the native.

[0130] Step S906: storing the native local storage data according to the key of the native local storage data and the value of the native local storage data.

[0131] In an exemplary embodiment of the present disclosure, the JavaScript bridge includes at least one of adding or modifying a JavaScript bridge, deleting a JavaScript bridge, and querying a JavaScript bridge.

[0132] In an exemplary embodiment of the present disclosure, Fig.10 As shown, cleaning and / or monitoring the stored data through the preset native call function includes:

[0133] Step S1002, calling a preset clear function to clear the local storage data of the H5 page.

[0134] In an exemplary embodiment of the present disclosure, Fig.11 As shown, cleaning and / or monitoring the stored data through the preset native call function includes:

[0135] Step S1102: When it is detected that the storage capacity of the native local storage data exceeds the preset storage capacity, a LRU (Least Recently Used) function is called to clean up the native local storage data.

[0136] In an exemplary embodiment of the present disclosure, Fig.12As shown, when it is detected that the storage amount of the native local storage data exceeds the preset storage amount, calling the LRU function to clean up the native local storage data includes:

[0137] Step S1202: when it is detected that the storage capacity of the native local storage data exceeds the preset storage capacity, the key of the native local storage data is obtained through the LRU function.

[0138] Step S1204: parsing the timestamp contained in the key of the native local storage data.

[0139] Step S1206: clean up the native local storage data according to the timestamp.

[0140] In an exemplary embodiment of the present disclosure, by obtaining the timestamp of the concatenated Key values, the data under the Key value with the smallest timestamp is removed.

[0141] In an exemplary embodiment of the present disclosure, Fig.13 As shown, cleaning and / or monitoring the stored data through the preset native call function includes:

[0142] Step S1302, when it is detected that the page is switched to the H5 page, query the JavaScript bridge to monitor whether the key of the URL of the currently visited page exists in the local storage data of the native.

[0143] In an exemplary embodiment of the present disclosure, Native Storage provides a JS bridge through the Call JS capability of JS Bridge to determine whether the local data of the current H5 page still exists. H5 can monitor the available status through the window and make a judgment not to use the local data access logic when the data is not available.

[0144] Specifically, when the client enters the H5 page, the Native Storage System will query whether there is local data with the current URL as the key (Note: when querying at this time, the timestamp spliced ​​when accessing data needs to be removed), and then synchronously return the query results to JS.

[0145] In an exemplary embodiment of the present disclosure, cookies are written according to preset cookie rules. Cookies can only be used in scenarios where there is public information that must be interacted between the client and the server, such as login information. It is recommended that the information placed in cookies be desensitized and does not involve the user's privacy information. Cookies are prohibited in the following scenarios:

[0146] 1.1. Cookies only save status information on the user side;

[0147] 1.2. Cookies are only used for messaging between different local pages;

[0148] 1.3. Read information from other channels on the client side and save it in Cookie;

[0149] 1.4. In scenarios where both LocalStorage and Cookies can be used, Cookies are not allowed to be used;

[0150] 1.5. Cookies used only in subdomains. Cookies stored in the root domain are prohibited.

[0151] 1.6. It is prohibited to write sensitive information such as user address information into Cookies.

[0152] 2) Cookie size limit:

[0153] 2.1. The key and value of the cookie should be as simple as possible, and the name should be as concise as possible. The value of a single cookie should not exceed 20 bytes.

[0154] Concise naming means shortening the length when naming. For example, sdkjskdjjkshdks=11. The key name is too long and completely unnecessary. You can directly name it sd=11. This can save bytes and reduce the size of the cookie.

[0155] 2.2. The upper limit for a single business cannot exceed 10.

[0156] 3) Cookie validity period limit:

[0157] 3.1. Cookies generally have a clear validity period. Persistent cookies will always be available during the validity period. Therefore, the validity period of a cookie cannot be set to infinity and should be reduced as much as possible in accordance with the business scenario.

[0158] 3.2. Give priority to using session cookies and do not use persistent cookies unless necessary.

[0159] In an exemplary embodiment of the present disclosure, Fig.14 As shown, the Cookie monitoring process 1400 includes:

[0160] Open the App to access an H5 page. When WebView is initialized, obtain the cookie under the root domain name and save the data. Then LoadUrl and inject the hookjsdocument.cookie code to report the content of the cookie written by the monitored JS through document.cookie. Here, it is necessary to determine whether the cookie written by JS is written under the root domain name. If it is only written under the second or third level domain name, no processing will be done. If it is written under the root domain name, the cookie content, size and current page URL will be reported to the monitoring platform.

[0161] When the page is exited, the cookie under the root domain name is obtained again, and a differential comparison is performed with the cookie in the WebView initialization phase and the difference is reported to the monitoring platform. This difference can be used to basically determine which cookies the current H5 page has written under the root domain name, and it serves as an important reference data for subsequent governance.

[0162] Specifically, take Android as an example: the normal startup phase of the program: onCreate()->onStart()->onResume(); the normal exit phase: onPause()->onStop()->onDestory(). In the onResume() phase, the H5 page has not yet been loaded. At this time, a String value is used to record the Cookie value (assuming it is Stringa) under the root domain name (for example, jd.com). Then in the onPause() phase, another String value is used to record the Cookie value at this time (assuming it is Stringb), and the difference between a and b is compared. The difference part represents the cookie written by the current page under the root domain name. The difference and the URL of the night page are reported, and the cookie value corresponding to the URL is analyzed later.

[0163] Based on this data, we can analyze the source of cookie writing, promote the rectification of related businesses, and finally formulate blacklists and whitelists.

[0164] In an exemplary embodiment of the present disclosure, Fig.15 As shown, the Cookie cleaning process 1500 includes:

[0165] 1) Configure the upper limit of cookie size, as well as cookie blacklist and whitelist on the configuration platform.

[0166] 2) After the App is started, the request interface obtains the cookie-related information configured on the configuration platform. At the same time, obtain the cookie size under the root domain name and compare it with the upper limit. If it exceeds the size limit, keep the key value under the whitelist and clear the rest; if there is no whitelist configured, clear it according to the key value of the blacklist, that is, the priority of the whitelist is higher than the blacklist. The priority of the whitelist is higher than the blacklist, and both are configurable. If there is a whitelist, do not pay attention to the blacklist, keep the whitelist data, and clear the rest. If the whitelist is empty, clear the blacklist content.

[0167] In an exemplary embodiment of the present disclosure, Fig.16 As shown, the Cookie cleaning process 1600 includes:

[0168] H5 uses JSBridge to achieve two-way communication between H5 and Native, thereby replacing H5 local storage with Native local storage. At the same time, further expansion and improvement are made in many aspects such as storage function and storage size limit.

[0169] Among them, the registered interface name is: NativeStorage.

[0170] The function name that defines JS calling Native is as follows:

[0171] Set a storage space size limit, such as 30M. If this limit is exceeded, data cleanup will be performed according to the rules set by NativeStorage.

[0172] 1. Basic data structure: stored in a new Key-Value format of Key:Key-Value.

[0173] Key: H5 URL, remove its query parameters and concatenate the timestamp when H5 calls any interface (format: https: / / xxx / xxx / timestamp), which is used for elimination algorithm).

[0174] Value: The original H5 local storage Key-Value is used as the Value, and the Value is completely determined by the caller. The purpose of increasing the Key value is to greatly reduce the probability of local data being overwritten when different H5 businesses use the same Key when storing.

[0175] 2. Basic functions: add, delete, modify and check.

[0176] Among them, the method names of localStorage are continued, and three JSBridges are provided for H5 to call: setItem (add and modify), removeItem (delete), and getItem (query). At the same time, the getAllKeys interface is provided for H5 to query all keys under the current page to prevent duplication of key values ​​when storing data.

[0177] Provides a clear function. The clear() here is different from the clear() of localStorage. It only clears the local data of the current H5 page, not the local data of the entire NativeStorage. The call example is as follows:

[0178] Store / change data: window.NativeStorage.callNative(setItem, data, "");

[0179] Get the number: window.NativeStorage.callNative(setItem, key, getItemCallback);

[0180] window.getItemCallbackse=function(result){

[0181] / / dosomething

[0182] }

[0183] 3. LRU elimination algorithm: eliminate the data that has not been used for the longest time.

[0184] When the local storage size limit is exceeded, the LRU algorithm is used to clear local data. By obtaining the timestamp of the key value splicing, the data under the key value with the smallest timestamp is removed.

[0185] 4. Available status monitoring:

[0186] Because there is a possibility that data may be cleared (due to factors such as exceeding the size limit, deleting the App and reinstalling it, being recycled by the system, etc.), NativeStorage will use the CallJS capability of JSBridge to provide a JS bridge to check whether the local data of the current H5 page still exists. H5 can monitor the available status through the window and make a judgment not to use the local data access logic when the data is not available.

[0187] Specifically, when the user enters the H5 page, NativeStorageSystem will query whether there is local data with the current URL as the key (Note: when querying at this time, the timestamp spliced ​​when accessing data needs to be removed), and then synchronously return the query results to JS.

[0188] Corresponding to the above method embodiment, the present disclosure also provides a processing device for an H5 request header, which can be used to execute the above method embodiment.

[0189] Fig.17 It is a block diagram of a device for processing an H5 request header in an exemplary embodiment of the present disclosure.

[0190] refer to Fig.17 , the H5 request header processing device 1700 may include:

[0191] The parsing module 1702 is configured to respond to a request to access an H5 page by parsing the request to determine a URL.

[0192] The loading module 1704 is configured to load a URL that passes a preset URL standard verification and inject a hook code.

[0193] The determination module 1706 is configured to determine a cookie written into the root domain name based on the JavaScript monitored by the hook code, and record it as the first cookie.

[0194] The determination module 1706 is configured to determine the Cookie under the root domain name when the exit from the H5 page is detected, and record it as the second Cookie.

[0195] The determination module 1706 is configured to determine a cleanup list for filtering cookies based on the first Cookie and the second Cookie.

[0196] In an exemplary embodiment of the present disclosure, the determination module 1706 is further configured to:

[0197] Calculate the cookie difference between the first cookie and the second cookie;

[0198] Associating the cookie difference with the URL of the currently visited page;

[0199] Parsing the Cookie difference according to the business processing scenario of the URL of the currently visited page;

[0200] Determine the cleanup list according to the analysis result, wherein the cleanup list includes a blacklist and / or a whitelist;

[0201] Set a limit range for cookie size based on the cleanup list.

[0202] In an exemplary embodiment of the present disclosure, the determination module 1706 is further configured to:

[0203] According to the analysis result, it is determined that the business processing scenario is at least one of the PIN for login, interface anti-theft and screen swiping prevention, and the whitelist is determined according to the Cookie corresponding to the Cookie difference.

[0204] In an exemplary embodiment of the present disclosure, the determination module 1706 is further configured to:

[0205] According to the analysis result, it is determined that the business processing scenario is at least one of data storage, cross-domain and embedding point, and the blacklist is determined according to the Cookie corresponding to the Cookie difference.

[0206] In an exemplary embodiment of the present disclosure, the H5 request header processing device 1700 is further used to:

[0207] After detecting that the application is started, determining whether the cookie in the request header for accessing the H5 page meets the cookie size limit range;

[0208] If the Cookie in the request header for accessing the H5 page is determined, only the key value of the Cookie that hits the whitelist is retained, and / or the key value of the Cookie that hits the blacklist is deleted.

[0209] In an exemplary embodiment of the present disclosure, the H5 request header processing device 1700 is further used to:

[0210] When detecting the request header of the H5 page accessing the network interface, if the HTTP error or exception code is 400 or 431, only the key value of the cookie hit by the whitelist is retained, and / or the key value of the cookie hit by the blacklist is deleted.

[0211] In an exemplary embodiment of the present disclosure, the H5 request header processing device 1700 is further used to:

[0212] Build a JavaScript bridge between the local storage of the H5 page and the native local storage;

[0213] Based on the JavaScript bridge, the local storage data of the H5 page is converted into native local storage data;

[0214] Clean and / or monitor the stored data through the preset native call function.

[0215] In an exemplary embodiment of the present disclosure, it further includes:

[0216] The URL without the query parameter is concatenated with the timestamp when any interface is called, and the concatenated result is determined as the key of the native local storage data.

[0217] The value of the local storage data of the H5 page is determined as the value of the local storage data of the native.

[0218] The native local storage data is stored according to the key of the native local storage data and the value of the native local storage data.

[0219] In an exemplary embodiment of the present disclosure, the JavaScript bridge includes at least one of adding or modifying a JavaScript bridge, deleting a JavaScript bridge, and querying a JavaScript bridge.

[0220] In an exemplary embodiment of the present disclosure, cleaning and / or monitoring stored data by using a preset native call function includes:

[0221] The preset clear function is called to clean up the local storage data of the H5 page.

[0222] In an exemplary embodiment of the present disclosure, cleaning and / or monitoring stored data by using a preset native call function includes:

[0223] When it is detected that the storage amount of the native local storage data exceeds the preset storage amount, the LRU function is called to clean up the native local storage data.

[0224] In an exemplary embodiment of the present disclosure, when it is detected that the storage amount of the native local storage data exceeds a preset storage amount, calling the LRU function to clean up the native local storage data includes:

[0225] When it is detected that the storage amount of the native local storage data exceeds the preset storage amount, the key of the native local storage data is obtained through the LRU function.

[0226] Parse the timestamp contained in the key of the native local storage data.

[0227] The native local storage data is cleaned up according to the timestamp.

[0228] In an exemplary embodiment of the present disclosure, cleaning and / or monitoring stored data by using a preset native call function includes:

[0229] When it is detected that the page is switched to the H5 page, the JavaScript bridge is queried to monitor whether the key of the URL of the currently visited page exists in the local storage data of the native.

[0230] Since the functions of the device 1700 have been described in detail in the corresponding method embodiments, the present disclosure will not elaborate on them here.

[0231] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.

[0232] In an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.

[0233] It will be appreciated by those skilled in the art that various aspects of the present invention may be implemented as a system, method or program product. Therefore, various aspects of the present invention may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to herein as a "circuit", "module" or "system".

[0234] Refer to the following Fig.18 18. An electronic device 1800 according to this embodiment of the present invention is described below. Fig.18 The electronic device 1800 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0235] like Fig.18 As shown, the electronic device 1800 is in the form of a general computing device. The components of the electronic device 1800 may include but are not limited to: at least one processing unit 1810, at least one storage unit 1820, and a bus 1830 connecting different system components (including the storage unit 1820 and the processing unit 1810).

[0236] The storage unit stores program codes, which can be executed by the processing unit 1810, so that the processing unit 1810 performs the steps according to various exemplary embodiments of the present invention described in the above “Exemplary Method” section of this specification. For example, the processing unit 1810 can perform the method shown in the embodiment of the present disclosure.

[0237] The storage unit 1820 may include a readable medium in the form of a volatile storage unit, such as a random access storage unit (RAM) 18201 and / or a cache storage unit 18202 , and may further include a read-only storage unit (ROM) 18203 .

[0238] The storage unit 1820 may also include a program / utility 18204 having a set (at least one) of program modules 18205, such program modules 18205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0239] Bus 1830 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.

[0240] The electronic device 1800 may also communicate with one or more external devices 1840 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a client to interact with the electronic device 1800, and / or communicate with any device that enables the electronic device 1800 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 1850. In addition, the electronic device 1800 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 1860. As shown, the network adapter 1860 communicates with other modules of the electronic device 1800 via a bus 1830. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 1800, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0241] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation of the present disclosure.

[0242] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible implementations, various aspects of the present invention can also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps according to various exemplary embodiments of the present invention described in the above "Exemplary Method" section of the present specification.

[0243] The program product for implementing the above method according to an embodiment of the present invention can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto, and in this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.

[0244] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0245] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0246] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.

[0247] Program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the client computing device, partially on the client device, as a separate software package, partially on the client computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the client computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).

[0248] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to an exemplary embodiment of the present invention, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.

[0249] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are to be considered exemplary only, and the true scope and concept of the present disclosure are indicated by the claims.

Claims

1. A method for processing an H5 request header, characterized in that: include: In response to a request to access an H5 page, parsing the request to determine a URL; Load the URL that passes the preset URL standard verification and inject the hook code; Determine the cookie written to the root domain name based on the JavaScript monitored by the hook code, and record it as the first cookie; When the exit from the H5 page is detected, the cookie under the root domain name is determined and recorded as the second cookie; A cleanup list for filtering cookies is determined based on the first Cookie and the second Cookie.

2. The method for processing the H5 request header according to claim 1, characterized in that: The cleanup list for filtering cookies determined according to the first cookie and the second cookie includes: Calculate the cookie difference between the first cookie and the second cookie; Associating the cookie difference with the URL of the currently visited page; Parsing the Cookie difference according to the business processing scenario of the URL of the currently visited page; Determine the cleanup list according to the analysis result, wherein the cleanup list includes a blacklist and / or a whitelist; Set a limit range for cookie size based on the cleanup list.

3. The method for processing the H5 request header according to claim 2, characterized in that: Determining the cleanup list according to the analysis result includes: According to the analysis result, it is determined that the business processing scenario is at least one of the PIN for login, interface anti-theft and screen swiping prevention, and the whitelist is determined according to the Cookie corresponding to the Cookie difference.

4. The method for processing the H5 request header according to claim 2, characterized in that: Determining the cleanup list according to the analysis result includes: According to the analysis result, it is determined that the business processing scenario is at least one of data storage, cross-domain and embedding point, and the blacklist is determined according to the Cookie corresponding to the Cookie difference.

5. The method for processing the H5 request header according to claim 2, characterized in that: Also includes: After detecting that the application is started, determining whether the cookie in the request header for accessing the H5 page meets the cookie size limit range; If the Cookie in the request header for accessing the H5 page is determined, only the key value of the Cookie that hits the whitelist is retained, and / or the key value of the Cookie that hits the blacklist is deleted.

6. The method for processing the H5 request header according to claim 2, characterized in that: Also includes: When detecting the request header of the H5 page accessing the network interface, if the HTTP error or exception code is 400 or 431, only the key value of the cookie hit by the whitelist is retained, and / or the key value of the cookie hit by the blacklist is deleted.

7. The method for processing an H5 request header according to any one of claims 1 to 6, characterized in that: Also includes: Build a JavaScript bridge between the local storage of the H5 page and the native local storage; Based on the JavaScript bridge, the local storage data of the H5 page is converted into native local storage data; Clean and / or monitor the stored data through the preset native call function.

8. The method for processing the H5 request header according to claim 7, characterized in that: Also includes: The URL without the query parameter is concatenated with the timestamp when any interface is called, and the concatenated result is determined as the key of the local storage data of the native; Determine the value of the local storage data of the H5 page as the value of the local storage data of the native; The native local storage data is stored according to the key of the native local storage data and the value of the native local storage data.

9. The method for processing an H5 request header according to claim 7, characterized in that: The JavaScript bridge includes at least one of adding or modifying a JavaScript bridge, deleting a JavaScript bridge, and querying a JavaScript bridge.

10. The method for processing the H5 request header according to claim 7, characterized in that: Cleaning and / or monitoring stored data through preset native call functions includes: The preset clear function is called to clean up the local storage data of the H5 page.

11. The method for processing an H5 request header according to claim 7, characterized in that: Cleaning and / or monitoring stored data through preset native call functions includes: When it is detected that the storage amount of the native local storage data exceeds the preset storage amount, the LRU function is called to clean up the native local storage data.

12. The method for processing an H5 request header according to claim 11, characterized in that: When it is detected that the storage amount of the native local storage data exceeds the preset storage amount, calling the LRU function to clean up the native local storage data includes: When it is detected that the storage amount of the native local storage data exceeds the preset storage amount, obtaining the key of the native local storage data through the LRU function; Parsing the timestamp contained in the key of the native local storage data; The native local storage data is cleaned up according to the timestamp.

13. The method for processing an H5 request header according to claim 7, characterized in that: Cleaning and / or monitoring stored data through preset native call functions includes: When it is detected that the page is switched to the H5 page, the JavaScript bridge is queried to monitor whether the key of the URL of the currently visited page exists in the local storage data of the native.

14. A device for processing an H5 request header, characterized in that: include: A parsing module, configured to respond to a request to access an H5 page and parse the request to determine a URL; Load the module, set it to load the URL that passes the preset URL standard validation, and inject the hook code; A determination module, configured to determine a cookie written into a root domain name based on the JavaScript monitored by the hook code, and record it as a first cookie; The determination module is configured to determine the cookie under the root domain name when the exit from the H5 page is detected, and record it as the second cookie; The determination module is configured to determine a cleanup list for filtering cookies based on the first Cookie and the second Cookie.

15. An electronic device, characterized in that: include: Memory; as well as A processor coupled to the memory, the processor being configured to execute the H5 request header processing method according to any one of claims 1 to 13 based on instructions stored in the memory.

16. A computer-readable storage medium having a program stored thereon, wherein when the program is executed by a processor, the method for processing an H5 request header as claimed in any one of claims 1 to 13 is implemented.