Method, device, electronic device and storage medium for generating Cookies
By unlocking the first thread after obtaining the benchmark cookie during the cookie generation process, the problem of slow cookie generation and easy blocking in the existing technology is solved, and more efficient cookie generation is achieved.
Patent Information
- Application Number
- CN202111599297.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-24
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2041-12-24
AI Technical Summary
In the existing cookie generation method, it is necessary to wait for the cookie to be verified and saved before unlocking the thread, resulting in a slow generation speed and easy to fall into a blocking operation state.
Generate candidate cookies by starting the first thread, and unlock the first thread after obtaining the baseline cookie, so that it can continue to generate the next candidate cookie, avoiding thread blocking and improving the generation speed.
There is no need to wait for the second thread to perform the verification work of candidate cookies to unlock the first thread, thereby increasing the speed of cookie generation, preventing thread blocking, and improving processing efficiency.
Smart Images

Figure CN114357328B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of Internet application technology, and in particular to a method, device, electronic device and storage medium for generating Cookies. Background Art
[0002] A cookie (also called HTTP Cookie, Web Cookie or browser Cookie) is a small piece of data sent by a server to a user's browser and saved locally. It will be carried and sent to the server when the browser makes another request to the same server.
[0003] Currently, developers are allowed to plant cookies on local clients by calling interfaces and other methods. Cookie planting allows cookies to be pre-set on local clients. Then, when the local client needs to load a Uniform Resource Locator (URL), it can carry the previously set cookie that matches the URL in the load request and then send the load request to the server.
[0004] However, in the current cookie planting method, the thread for generating cookies needs to be unlocked only after the cookie is verified and saved. The slow unlocking timing causes the thread for generating cookies to easily fall into a blocking operation state, making the cookie generation speed slow. Summary of the invention
[0005] The embodiments of the present disclosure provide a method, device, electronic device, and storage medium for generating Cookies, thereby increasing the speed of Cookie generation.
[0006] According to one aspect of an embodiment of the present disclosure, a method for generating a cookie is provided. The method for generating a cookie comprises:
[0007] Initiate a first thread, wherein the first thread is adapted to generate at least one candidate cookie corresponding to a preset uniform resource locator;
[0008] In response to the first thread generating the candidate Cookie, locking the first thread so that the first thread stops generating the candidate Cookie, and starting the second thread to obtain a reference Cookie corresponding to the uniform resource locator, wherein the reference Cookie is used to verify the candidate Cookie;
[0009] In response to the second thread acquiring the reference Cookie, the first thread is unlocked to enable the first thread to continue to generate a next candidate Cookie.
[0010] In an exemplary embodiment, in response to the first thread generating the candidate cookie, locking the first thread so that the first thread stops generating the candidate cookie, and starting the second thread to obtain the reference cookie corresponding to the uniform resource locator includes:
[0011] In response to the first thread generating the candidate cookie, locking the first thread so that the first thread stops generating the candidate cookie, and checking the uniform resource locator;
[0012] In response to the uniform resource locator passing the check, the second thread is initiated to obtain a reference Cookie corresponding to the uniform resource locator.
[0013] In an exemplary embodiment, the starting of the second thread to obtain a reference Cookie corresponding to the uniform resource locator includes:
[0014] Start the second thread to obtain the local cookie set from the local cookie database;
[0015] The local cookie in the local cookie set and corresponding to the uniform resource locator is determined as the reference cookie.
[0016] In an exemplary embodiment, the method further comprises: starting a third thread, the third thread being adapted to access the local cookie database;
[0017] The starting of the second thread to obtain the local Cookie set from the local Cookie database includes:
[0018] The local cookie set obtained by the third thread from the local cookie database is provided to the second thread.
[0019] In an exemplary embodiment, the method further includes: verifying the candidate Cookie using the benchmark Cookie.
[0020] In an exemplary embodiment, the verifying the candidate Cookie using the reference Cookie includes:
[0021] If the candidate Cookie does not include the security attribute and the reference Cookie includes the security attribute, determining that the candidate Cookie does not pass the verification;
[0022] In the case that the candidate Cookie does not contain a valid time attribute and the reference Cookie contains a valid time attribute, it is determined that the candidate Cookie does not pass the verification.
[0023] In an exemplary embodiment, the method further includes:
[0024] In response to successfully verifying the candidate cookie using the benchmark cookie, the candidate cookie is saved to the set of planted cookies in the memory.
[0025] In an exemplary embodiment, the method further includes:
[0026] In response to a determination operation for a target uniform resource locator, extracting a cookie corresponding to the target uniform resource locator from the planted cookie set;
[0027] The cookie corresponding to the target uniform resource locator is determined as a standby cookie of the target uniform resource locator.
[0028] According to another aspect of an embodiment of the present disclosure, a device for generating a cookie is provided. The device for generating a cookie includes:
[0029] A first starting module is configured to start a first thread, wherein the first thread is adapted to generate at least one candidate Cookie corresponding to a preset uniform resource locator;
[0030] a locking module, configured to, in response to the first thread generating the candidate Cookie, lock the first thread so that the first thread stops generating the candidate Cookie, and start a second thread to obtain a reference Cookie corresponding to the uniform resource locator, wherein the reference Cookie is used to verify the candidate Cookie;
[0031] The unlocking module is configured to unlock the first thread in response to the second thread acquiring the reference Cookie so that the first thread continues to generate the next candidate Cookie.
[0032] In an exemplary embodiment, the locking module is configured to, in response to the first thread generating the candidate cookie, lock the first thread so that the first thread stops generating the candidate cookie and checks the uniform resource locator; in response to the uniform resource locator passing the check, start the second thread to obtain a baseline cookie corresponding to the uniform resource locator.
[0033] In an exemplary embodiment, the locking module is configured to start the second thread to obtain a local cookie set from a local cookie database; and determine a local cookie in the local cookie set that corresponds to the uniform resource locator as the reference cookie.
[0034] In an exemplary embodiment, the locking module is configured to start a third thread, where the third thread is adapted to access the local cookie database; and provide the local cookie set obtained by the third thread from the local cookie database to the second thread.
[0035] In an exemplary embodiment, it also includes:
[0036] The verification module is configured to verify the candidate Cookie using the benchmark Cookie.
[0037] In an exemplary embodiment, the verification module is configured to determine that the candidate cookie fails the verification when the candidate cookie does not contain a security attribute and the benchmark cookie contains a security attribute; and to determine that the candidate cookie fails the verification when the candidate cookie does not contain a valid time attribute and the benchmark cookie contains a valid time attribute.
[0038] In an exemplary embodiment, the verification module is configured to save the candidate cookie into a set of planted cookies in memory in response to successfully verifying the candidate cookie using the benchmark cookie.
[0039] In an exemplary embodiment, it also includes:
[0040] The determination module is configured to extract the cookie corresponding to the target uniform resource locator from the planted cookie set in response to a determination operation on the target uniform resource locator; and determine the cookie corresponding to the target uniform resource locator as a standby cookie for the target uniform resource locator.
[0041] According to another aspect of the present disclosure, an electronic device is provided. The electronic device includes:
[0042] processor;
[0043] a memory for storing instructions executable by the processor;
[0044] The processor is used to read the executable instructions from the memory and execute the instructions to implement the method for generating Cookie as described in any one of the above items.
[0045] According to another aspect of an embodiment of the present disclosure, there is provided a computer-readable storage medium having computer instructions stored thereon, wherein the instructions, when executed by a processor, implement the method for generating Cookie as described in any one of the above items.
[0046] According to another aspect of an embodiment of the present disclosure, a computer program product is provided, including a computer program, which implements the above-mentioned method of generating Cookie when executed by a processor.
[0047] The technical solution provided by the embodiments of the present disclosure may at least include the following beneficial effects: there is no need to wait for the second thread to perform the verification of the candidate Cookie. When the second thread obtains the reference Cookie for verifying the candidate Cookie, the first thread for generating the candidate Cookie is unlocked, thereby solving the blocking problem of the first thread and improving the generation speed of the candidate Cookie.
[0048] 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
[0049] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0050] Figure 1 is a flow chart of a method for planting Cookies according to an exemplary embodiment;
[0051] Figure 2 is a flowchart of a method for generating Cookie according to an exemplary embodiment;
[0052] Figure 3 is a first exemplary flow chart of a method for planting Cookies according to an exemplary embodiment;
[0053] Figure 4 is a second exemplary flow chart of a method for planting Cookies according to an exemplary embodiment;
[0054] Figure 5 is a structural diagram of a device for generating Cookie according to an exemplary embodiment;
[0055] Figure 6 is a structural diagram of an electronic device according to an exemplary embodiment;
[0056] Figure 7 is a structural diagram of a device for generating Cookie according to an exemplary embodiment;
[0057] Figure 8 It is a structural diagram of another device for generating Cookie according to an exemplary embodiment. DETAILED DESCRIPTION
[0058] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0059] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0060] The method for generating Cookies provided by the present disclosure can be applied to an application environment where Cookies are planted. For example, it can be applied to an application environment where Cookies are planted in a local client (e.g., a mobile client) with a browser using a Web storage API mechanism or an IndexedDB mechanism. It can also be applied to an application environment where a developer calls a relevant interface of a mobile operating system to plant Cookies in a local client with a browser. Among them, mobile operating systems may include but are not limited to: Android, iOS, Windows phone, Symbian, BlackBerry, Windows Mobile, Harmony, or Freeme OS, etc.
[0061] The following explains the terms involved in the embodiments of the present disclosure.
[0062] Thread: It is the smallest unit that the operating system can schedule operations. It is contained in the process and is the actual operation unit in the process. A thread refers to a single sequential control flow in the process. A process can have multiple threads running concurrently, and each thread executes different tasks in parallel.
[0063] The domain attribute of the cookie specifies the website or domain that can access the cookie. The cookie mechanism does not follow a strict same-origin policy, allowing a subdomain to set or get cookies of its parent domain.
[0064] Cookie path attribute: indicates the directory where the cookie is located. The default value of asp.net is / , which is the root directory. On the same server, there are the following directories: / test / , / test / cd / , / test / dd / . Assuming that the path of Cookie1 is / test / and the path of Cookie2 is / test / cd / , all pages under the test directory can access Cookie1, while the subpages of / test / and / test / dd / cannot access Cookie2.
[0065] Cookie's Security (Secure) attribute: specifies whether to use the HTTPS security protocol to send cookies. Using the HTTPS security protocol can protect cookies from being stolen and tampered with during transmission between the browser and the Web server.
[0066] The expiration time (Expires) attribute of the cookie is used to set the lifetime of the cookie. There are two types of storage cookies: session and persistent. When the Expires attribute is set to default, it is a session cookie, which is only stored in the client memory and expires when the user closes the browser; persistent cookies are stored in the user's hard disk and will not expire until the lifetime expires or the user directly clicks a button such as "Logout" on the web page to end the session.
[0067] Figure 1 The figure is a flow chart of a method for planting Cookies according to an exemplary embodiment.
[0068] exist Figure 1 In the method, the first thread is used to generate a cookie corresponding to a predetermined URL (for example, the URL is determined based on user input) to be planted in the local client, and the cookie is called a candidate cookie; the second thread is used to extract a reference cookie from a local cookie database storing local cookies, and the reference cookie is used to verify the candidate cookie; the third thread is used to access the local cookie database storing local cookies. The local cookie database is usually stored in the storage medium of the local client. Among them: the first thread, the second thread and the third thread can belong to the same APP running in the local client, or they can each belong to different APPs running in the local client.
[0069] In the ith cookie planting:
[0070] The first thread generates a single Cookie 1 to be planted corresponding to a first URL, wherein the first URL may be provided by a user. The first thread further checks the first URL. When the first URL is found to be incorrect during the checking process, the first thread further repairs the first URL (e.g., corrects the error description in the first URL). After the checking and repairing are completed, the first thread is locked. The locked first thread stops generating cookies.
[0071] After locking the first thread, start the second thread.
[0072] After the second thread is started, it is determined whether the initialization of the second thread is completed based on whether the second thread can access the planted Cookie set in the memory, wherein when the second thread can access the planted Cookie set, it is determined that the initialization of the second thread is completed, and when the second thread cannot access the planted Cookie set, it is determined that the initialization of the second thread is not completed. Here, the planted Cookie set is a set of Cookies that have been planted in the local client and saved in the memory. When the memory loses power, the planted Cookie set in the memory may be lost, and initialization failure may occur. When the second thread is closed, the second thread cannot normally access the planted Cookie set, which may also cause initialization failure.
[0073] When it is determined that the initialization of the second thread is not completed, the initialization work of the second thread is executed. The initialization work of the second thread specifically includes: the third thread obtains the local cookie set from the local cookie database; the second thread obtains the local cookie set from the third thread, and writes the local cookie set into the memory as the planted cookie set. The local cookie set is a collection of cookies that have been planted in the local client and saved in the local database. Here, in the event of a power failure in the memory, the first thread, the second thread, and the third thread being shut down, etc., the data in the local cookie set will not be lost.
[0074] After the initialization of the second thread is completed, the second thread verifies Cookie 1 generated by the first thread using the local Cookie set obtained from the local Cookie database by the third thread as the already planted Cookie set in the memory, wherein the Cookie 1 that passes the verification is saved in the already planted Cookie set in the memory. The second thread also sends the Cookie 1 that passes the verification to the third thread, so that the third thread saves the Cookie 1 that passes the verification in the local Cookie database. After the Cookie 1 generated by the first thread is saved in the memory and the local Cookie database, the second thread sends an unlock instruction to the first thread.
[0075] The first thread completes unlocking based on the unlocking instruction. At this point, the planting work for Cookie1 is completed.
[0076] After the first thread completes unlocking, the i+1th cookie planting can be performed. The i+1th cookie planting process refers to the i-th cookie planting process described above.
[0077] It can be seen that in Figure 1 In the method flow shown, the first thread is unlocked only after the cookie is verified and saved, which makes the first thread easily fall into a blocking operation state, making the cookie generation speed slow. Figure 1 In the method flow shown, when N (N is a positive integer greater than 1) cookies are set for the same URL, N URL check and correction operations and N locking and unlocking operations need to be performed, thereby increasing processing time.
[0078] Taking into account Figure 1 The process shown is an example of many defects in cookie planting. The present disclosure proposes a method for generating cookies, which can prevent thread blocking and increase the speed of cookie generation.
[0079] Figure 2 FIG. 1 is a flowchart of a method for generating Cookies according to an exemplary embodiment. Figure 2 As shown, the method includes:
[0080] Step 101: Start a first thread, wherein the first thread is adapted to generate at least one candidate Cookie corresponding to a preset URL.
[0081] Here, the preset URL may be a URL entered by a user in an input interface such as an address bar of a browser. The first thread is adapted to generate at least one candidate cookie corresponding to the preset URL. When the first thread is in a locked state, the generation of candidate cookies is stopped; when the first thread is not in a locked state, the generation of candidate cookies continues until a stop instruction is received and the generation of candidate cookies is stopped.
[0082] The applicable scope of the candidate Cookie corresponds to the specific elements contained in the URL. For example, when the URL is "www.aaa.com", the candidate Cookie generated by the first thread is applicable to all pages under "www.aaa.com" (for example, www.aaa.com / P / 111).
[0083] For another example, when the URL is "www.aaa.com / P / 123", the candidate cookie generated by the first thread is applicable to all pages under "www.aaa.com / P / 123", but not to the parent pages (for example, "www.aaa.com / P") or the same-level pages (for example, "www.aaa.com / P / 456") of "www.aaa.com / P / 123".
[0084] Step 102: In response to the first thread generating the candidate cookie, the first thread is locked so that the first thread stops generating the candidate cookie, and the second thread is started to obtain a reference cookie corresponding to the URL, wherein the reference cookie is used to verify the candidate cookie.
[0085] Step 103: In response to the second thread acquiring the reference Cookie, unlocking the first thread so that the first thread continues to generate the next candidate Cookie.
[0086] It can be seen that the present invention does not wait for the second thread to complete Cookie verification and saving before unlocking the first thread, but when the second thread used to obtain the benchmark Cookie obtains the benchmark Cookie, the first thread is unlocked to enable the first thread to continue to generate the next candidate Cookie (that is, the subsequent candidate Cookie), which can prevent the first thread from being blocked and improve the Cookie generation speed of the first thread.
[0087] In an exemplary embodiment, in response to the first thread generating the candidate cookie, locking the first thread so that the first thread stops generating the candidate cookie, and starting the second thread to obtain a baseline cookie corresponding to the URL includes: in response to the first thread generating the candidate cookie, locking the first thread so that the first thread stops generating the candidate cookie, and checking the URL; in response to the URL passing the check, starting the second thread to obtain the baseline cookie corresponding to the URL.
[0088] It can be seen that the present disclosure does not start the second thread after the first thread is locked, but starts the second thread after the first thread generates a candidate cookie and determines that the URL passes the check. By starting the second thread as soon as possible, the processing speed is improved.
[0089] In an exemplary embodiment, starting the second thread to obtain a reference cookie corresponding to the URL includes: starting the second thread to obtain a local cookie set from a local cookie database; and determining a local cookie in the local cookie set corresponding to the URL as a reference cookie.
[0090] It can be seen that the present disclosure can improve the speed of determining the benchmark Cookie by using the local Cookie set. In an exemplary embodiment, the method further includes: starting a third thread, the third thread is adapted to access the local Cookie database; starting the second thread to obtain the local Cookie set from the local Cookie database includes: providing the local Cookie set obtained by the third thread from the local Cookie database to the second thread.
[0091] It can be seen that the present disclosure provides a local cookie set for the second thread through the cooperation between the second thread and the third thread. Since the database access work is shared to the third thread for execution, the processing pressure of the second thread is reduced.
[0092] In an exemplary embodiment, the method further includes: verifying the candidate Cookie using a reference Cookie. Here, the reference Cookie serves as a reference object for the newly generated candidate Cookie, and can verify whether the newly generated candidate Cookie is correct.
[0093] It can be seen that using the benchmark Cookies in the local Cookie set to verify the newly generated candidate Cookies improves the accuracy of the newly generated candidate Cookies and can avoid generating erroneous candidate Cookies.
[0094] In an exemplary embodiment, a specific method of determining the reference Cookie includes at least one of the following:
[0095] (1) The local cookie in the local cookie set that corresponds to the same URL as the candidate cookie generated by the first thread is determined as the reference cookie.
[0096] (2) A local cookie in the local cookie set that has a domain attribute, a path attribute, and a key name that matches the candidate cookie generated by the first thread is determined as a benchmark cookie.
[0097] (3) The local cookies in the local cookie set that correspond to the same URL as the candidate cookies generated by the first thread and have matching domain attributes, path attributes and key names are determined as the benchmark cookies.
[0098] Therefore, through multiple dimensions such as URL, domain attributes, path attributes and key name, the benchmark cookie that serves as the verification object for the newly generated cookie can be accurately determined.
[0099] In an exemplary embodiment, verifying the candidate cookie based on the reference cookie includes:
[0100] (1) When the candidate Cookie generated by the first thread does not contain security attributes and the reference Cookie contains security attributes, it is determined that the candidate Cookie generated by the first thread does not pass the verification.
[0101] Therefore, considering the security of Cookie, when the reference Cookie contains security attributes, it is determined that the candidate Cookie generated by the first thread should also contain security attributes. Otherwise, when the candidate Cookie generated by the first thread does not contain security attributes, it is determined that the candidate Cookie generated by the first thread does not pass the verification.
[0102] (2) When the candidate Cookie generated by the first thread does not contain a valid time attribute and the reference Cookie contains a valid time attribute, it is determined that the candidate Cookie generated by the first thread does not pass the verification.
[0103] Therefore, considering the validity of Cookie related to time, when the reference Cookie contains the time attribute, it is determined that the candidate Cookie generated by the first thread should also contain the time attribute. Otherwise, when the candidate Cookie generated by the first thread does not contain the time attribute, it is determined that the candidate Cookie generated by the first thread does not pass the verification.
[0104] The above exemplary descriptions are typical examples of determining a baseline cookie and verifying a candidate cookie. Those skilled in the art will appreciate that such descriptions are merely exemplary and are not intended to limit the scope of protection of the embodiments of the present invention.
[0105] In an exemplary embodiment, the method further includes: in response to successfully verifying the candidate cookie using the benchmark cookie, saving the candidate cookie to a set of planted cookies in memory.
[0106] It can be seen that the present invention achieves successful planting of the candidate Cookie by saving the successfully verified candidate Cookie into the set of already planted Cookies in the memory.
[0107] In an exemplary embodiment, the method further includes: in response to a determination operation for a target URL, extracting a cookie corresponding to the target URL from a set of planted cookies; and determining the cookie corresponding to the target URL as a planted cookie of the target URL.
[0108] For example, when it is detected that the URL: www.abc.com is entered in the browser, www.abc.com is the target URL. At this time, the cookie corresponding to "www.abc.com" can be extracted from the set of already planted cookies in the memory, and the extracted cookie can be used as a standby cookie applicable to all pages under "www.abc.com". Then, all pages under "www.abc.com" can use the extracted standby cookie to execute specific page logic. For example, the standby cookie can be used to identify the user, or the standby cookie can be used to temporarily store data in a cache such as a shopping cart, etc.
[0109] Figure 3 It is a first exemplary flow chart of a method for planting Cookies according to an exemplary embodiment.
[0110] exist Figure 3In the method, the first thread is used to generate a cookie corresponding to a predetermined URL (for example, the URL is determined based on user input) to be planted in the local client, and the cookie is called a candidate cookie; the second thread is used to extract a reference cookie from a local cookie database storing local cookies, and the reference cookie is used to verify the candidate cookie; the third thread is used to access the local cookie database storing local cookies. The local cookie database is usually stored in the storage medium of the local client. Among them: the first thread, the second thread and the third thread can belong to the same APP running in the local client, or they can each belong to different APPs running in the local client.
[0111] In the ith cookie planting:
[0112] The first thread generates Cookie 1 corresponding to the first URL, wherein the first URL can be provided by the user. The first thread checks the first URL. When the first URL is found to be incorrect during the checking process, the first thread further repairs the first URL (for example, corrects the error description in the first URL). After the checking and repairing are completed, the first thread is locked. The locked first thread stops generating Cookies. Among them, between the first thread generating Cookie 1 and locking the first thread, the second thread is started. For example, the second thread can be started during the checking and repairing process.
[0113] After the second thread is started, it is determined whether the initialization of the second thread is completed based on whether the second thread can access the planted Cookie set in the memory, wherein when the second thread can access the planted Cookie set, it is determined that the initialization of the second thread is completed, and when the second thread cannot access the planted Cookie set, it is determined that the initialization of the second thread is not completed. Here, the planted Cookie set is a set of Cookies that have been planted in the local client and saved in the memory. When the memory loses power, the planted Cookie set in the memory may be lost, and initialization failure may occur. When the second thread is closed, the second thread cannot normally access the planted Cookie set, which may also cause initialization failure.
[0114] When it is determined that the initialization of the second thread is not completed, the initialization work of the second thread is executed, and the initialization work of the second thread specifically includes: the third thread obtains the local cookie set from the local cookie database; the second thread obtains the local cookie set from the third thread, and writes the local cookie set into the memory as the planted cookie set. The local cookie set is a set of cookies that have been planted in the local client and saved in the local database. Here, in the case of power failure in the memory, the first thread, the second thread and the third thread being closed, etc., the data in the local cookie set will not be lost.
[0115] After the initialization of the second thread is completed, the second thread can execute the unlocking process of the first thread, including: the second thread generates an unlocking instruction and sends the unlocking instruction to the first thread. The first thread completes the unlocking based on the received unlocking instruction and can immediately continue the subsequent cookie generation work. Synchronously, after the initialization of the second thread is completed, the second thread uses the local cookie set obtained from the local cookie database by the third thread as the planted cookie set in the memory to verify the Cookie 1 generated by the first thread, wherein the Cookie 1 that passes the verification is saved to the planted cookie set in the memory. The second thread also sends the Cookie 1 that passes the verification to the third thread, so that the third thread saves the Cookie 1 that passes the verification into the local cookie database.
[0116] After the first thread completes unlocking, the i+1th cookie planting can be performed. The i+1th cookie setting process refers to the i-th cookie planting described above.
[0117] It can be seen that compared Figure 1 In the process shown, the first thread is unlocked without waiting for the second thread to perform the Cookie verification work, so the first thread can be unlocked faster, thereby generating Cookie faster.
[0118] Figure 4 is a second exemplary flow chart of a method for planting Cookies according to an exemplary embodiment.
[0119] exist Figure 4In the method, the first thread is used to generate a cookie corresponding to a predetermined URL (for example, the URL is determined based on user input) to be planted in the local client, and the cookie is called a candidate cookie; the second thread is used to extract a reference cookie from a local cookie database storing local cookies, and the reference cookie is used to verify the candidate cookie; the third thread is used to access the local cookie database storing local cookies. The local cookie database is usually stored in the storage medium of the local client. Among them: the first thread, the second thread and the third thread can belong to the same APP running in the local client, or they can each belong to different APPs running in the local client.
[0120] In the ith cookie planting:
[0121] The first thread generates N cookies corresponding to the first URL, specifically Cookie1 to Cookie N, where the first URL can be provided by the user, and N is a positive integer greater than 1. The first thread checks the first URL. When the first URL is found to be incorrect during the inspection process, the first thread further repairs the first URL (for example, corrects the error description in the first URL). After the inspection and repair are completed, the first thread is locked. The locked first thread stops generating cookies. Among them, between generating N cookies and locking the first thread, the second thread is started. For example, the second thread can be started during the inspection and repair process.
[0122] After the second thread is started, it is determined whether the initialization of the second thread is completed based on whether the second thread can access the planted Cookie set in the memory, wherein when the second thread can access the planted Cookie set, it is determined that the initialization of the second thread is completed, and when the second thread cannot access the planted Cookie set, it is determined that the initialization of the second thread is not completed. Here, the planted Cookie set is a set of Cookies that have been planted in the local client and saved in the memory. When the memory loses power, the planted Cookie set in the memory may be lost, and initialization failure may occur. When the second thread is closed, the second thread cannot normally access the planted Cookie set, which may also cause initialization failure.
[0123] When it is determined that the initialization of the second thread is not completed, the initialization work of the second thread is executed, and the initialization work of the second thread specifically includes: the third thread obtains the local cookie set from the local cookie database; the second thread obtains the local cookie set from the third thread, and writes the local cookie set into the memory as the planted cookie set. The local cookie set is a set of cookies that have been planted in the local client and saved in the local database. Here, in the case of power failure in the memory, the first thread, the second thread and the third thread being closed, etc., the data in the local cookie set will not be lost.
[0124] After the initialization of the second thread is completed, the second thread can execute the unlocking process of the first thread, including: the second thread generates an unlocking instruction and sends the unlocking instruction to the first thread. The first thread completes the unlocking based on the received unlocking instruction and can immediately continue the subsequent cookie generation work. Synchronously, after the initialization of the second thread is completed, the second thread can also use the local cookie set obtained from the local cookie database by the third thread as the planted cookie set in the memory to verify Cookie1~CookieN generated by the first thread. Assuming that Cookie1~CookieK passes the verification (K is less than N), the verified Cookie1~CookieK will be saved to the planted cookie set in the memory respectively. The second thread also sends the verified Cookie1~CookieK to the third thread, so that the third thread can save the verified Cookie1~CookieK to the local cookie database.
[0125] After the first thread completes unlocking, the i+1th cookie planting can be performed. The i+1th cookie setting process refers to the i-th cookie planting described above.
[0126] It can be seen that compared Figure 1 The process shown in the figure does not need to wait for the second thread to perform the verification work before unlocking the first thread. The first thread can be unlocked faster, thereby generating cookies faster. Moreover, compared with Figure 1 In the process shown, for multiple cookies of the same URL, only one locking and one unlocking operation need to be performed, thereby saving processing time and achieving process optimization.
[0127] Figure 5 FIG. 1 is a structural diagram of a device for generating Cookies according to an exemplary embodiment. Figure 5 As shown, the device 500 for generating Cookie includes:
[0128] A first starting module 501 is configured to start a first thread, wherein the first thread is adapted to generate at least one candidate Cookie corresponding to a preset URL;
[0129] The locking module 502 is configured to, in response to the first thread generating the candidate cookie, lock the first thread so that the first thread stops generating the candidate cookie, and start the second thread to obtain a reference cookie corresponding to the URL, wherein the reference cookie is used to verify the candidate cookie;
[0130] The unlocking module 503 is configured to unlock the first thread in response to the second thread acquiring the reference Cookie so that the first thread continues to generate the next candidate Cookie.
[0131] In an exemplary embodiment, the locking module 502 is configured to, in response to the first thread generating the candidate cookie, lock the first thread so that the first thread stops generating the candidate cookie and checks the URL; in response to the URL passing the check, start the second thread to obtain the baseline cookie corresponding to the URL.
[0132] In an exemplary implementation, the locking module 502 is configured to start the second thread to obtain a local cookie set from a local cookie database; and determine the local cookie in the local cookie set corresponding to the uniform resource locator as the reference cookie.
[0133] In an exemplary implementation, the locking module 502 is configured to start a third thread, where the third thread is adapted to access the local cookie database; and provide the local cookie set obtained by the third thread from the local cookie database to the second thread.
[0134] In an exemplary embodiment, a verification module 504 is also included, which is configured to verify the candidate Cookie using the reference Cookie.
[0135] In an exemplary embodiment, the verification module 504 is configured to determine that the candidate cookie fails the verification when the candidate cookie does not contain a security attribute and the benchmark cookie contains a security attribute; and to determine that the candidate cookie fails the verification when the candidate cookie does not contain a valid time attribute and the benchmark cookie contains a valid time attribute.
[0136] In an exemplary embodiment, the verification module 504 is configured to save the candidate cookie into the set of planted cookies in the memory in response to successfully verifying the candidate cookie using the benchmark cookie.
[0137] In an exemplary embodiment, it also includes a determination module 505, which is configured to extract a cookie corresponding to the target uniform resource locator from the planted cookie set in response to a determination operation on the target uniform resource locator; and determine the cookie corresponding to the target uniform resource locator as a standby cookie for the target URL.
[0138] An embodiment of the present application also provides an electronic device. Figure 6 FIG. 1 is a structural diagram of an electronic device according to an exemplary embodiment. Figure 6 As shown, the electronic device 600 may include: a processor 601; a memory 602 for storing executable instructions of the processor 601; wherein the processor 601 is configured to: when executing the executable instructions stored in the memory 602, implement the method for generating Cookies provided in the embodiment of the present disclosure.
[0139] It can be understood that the electronic device 600 can be a server or a terminal device. In specific applications, the terminal device can be a mobile phone, a computer, a digital broadcast terminal, a message sending and receiving device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0140] Figure 7 700 is a structural diagram of a device for generating Cookies according to an exemplary embodiment. For example, the device 700 may be: a smart phone, a tablet computer, a Moving Picture Experts Group Audio Layer III (MP3) player, a Moving Picture Experts Group Audio Layer IV (MP4) player, a laptop computer or a desktop computer. The device 700 may also be referred to as a user device, a portable terminal, a laptop terminal, a desktop terminal or other names.
[0141] Typically, the device 700 includes a processor 701 and a memory 702 .
[0142] The processor 701 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 701 may be implemented in at least one hardware form of digital signal processing (DSP), field programmable gate array (FPGA), and programmable logic array (PLA). The processor 701 may also include a main processor and a coprocessor. The main processor is a processor for processing data in an awake state, also known as a central processing unit (CPU); the coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 701 may be integrated with a graphics processing unit (GPU), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 701 may also include an artificial intelligence (AI) processor, which is used to process computing operations related to machine learning.
[0143] The memory 702 may include one or more computer-readable storage media, which may be non-transitory. The memory 702 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices and flash memory storage devices.
[0144] In some embodiments, the non-transitory computer-readable storage medium in the memory 702 is used to store at least one instruction, which is used to be executed by the processor 701 to implement the method for generating Cookies provided in various embodiments of the present disclosure. In some embodiments, the device 700 may also optionally include: a peripheral device interface 703 and at least one peripheral device. The processor 701, the memory 702 and the peripheral device interface 703 may be connected via a bus or a signal line. Each peripheral device may be connected to the peripheral device interface 703 via a bus, a signal line or a circuit board. Specifically, the peripheral device includes: at least one of a radio frequency circuit 704, a touch display screen 705, a camera assembly 706, an audio circuit 707, a positioning assembly 708 and a power supply 709.
[0145] The peripheral device interface 703 may be used to connect at least one peripheral device related to input / output (I / O) to the processor 701 and the memory 702. In some embodiments, the processor 701, the memory 702, and the peripheral device interface 703 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 701, the memory 702, and the peripheral device interface 703 may be implemented on a separate chip or circuit board, which is not limited in this embodiment.
[0146] The radio frequency circuit 704 is used to receive and transmit radio frequency (RF) signals, also known as electromagnetic signals. The radio frequency circuit 704 communicates with communication networks and other communication devices through electromagnetic signals. The radio frequency circuit 704 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals into electrical signals. Optionally, the radio frequency circuit 704 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and the like. The radio frequency circuit 704 can communicate with other terminals through at least one wireless communication protocol. The wireless communication protocol includes, but is not limited to: a metropolitan area network, various generations of mobile communication networks (2G, 3G, 4G and 5G), a wireless local area network and / or a wireless fidelity (Wireless Fidelity, WiFi) network. In some embodiments, the radio frequency circuit 704 may also include circuits related to near field communication (NFC), which is not limited in the present disclosure.
[0147] The display screen 705 is used to display the user interface (UI). The UI may include graphics, text, icons, videos, and any combination thereof. When the display screen 705 is a touch display screen, the display screen 705 also has the ability to collect touch signals on the surface or above the surface of the display screen 705. The touch signal can be input to the processor 701 as a control signal for processing. At this time, the display screen 705 can also be used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, the display screen 705 can be one, and the front panel of the device 700 is set; in other embodiments, the display screen 705 can be at least two, which are respectively set on different surfaces of the device 700 or are folded; in some other embodiments, the display screen 705 can be a flexible display screen, which is set on the curved surface or folded surface of the device 700. Even, the display screen 705 can also be set to a non-rectangular irregular shape, that is, a special-shaped screen. The display screen 705 can be made of materials such as liquid crystal display (LCD), organic light-emitting diode (OLED), etc.
[0148] The camera assembly 706 is used to capture images or videos. Optionally, the camera assembly 706 includes a front camera and a rear camera. Typically, the front camera is arranged on the front panel of the terminal, and the rear camera is arranged on the back of the terminal. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize the panoramic shooting and the virtual reality (VR) shooting function or other fusion shooting functions. In some embodiments, the camera assembly 706 may also include a flash. The flash can be a monochrome temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cold light flash, which can be used for light compensation at different color temperatures.
[0149] The audio circuit 707 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, and convert the sound waves into electrical signals and input them into the processor 701 for processing, or input them into the radio frequency circuit 704 to achieve voice communication. For the purpose of stereo acquisition or noise reduction, there may be multiple microphones, which are respectively arranged at different parts of the device 700. The microphone may also be an array microphone or an omnidirectional acquisition microphone. The speaker is used to convert the electrical signal from the processor 701 or the radio frequency circuit 704 into sound waves. The speaker may be a traditional film speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert the electrical signal into sound waves audible to humans, but also convert the electrical signal into sound waves inaudible to humans for purposes such as ranging. In some embodiments, the audio circuit 707 may also include a headphone jack.
[0150] Positioning component 708 is used to locate the current geographic location of device 700 to implement navigation or location-based services (LBS). Positioning component 708 can be a positioning component based on the Global Positioning System (GPS) of the United States, the Beidou system of China, the Grenades system of Russia, or the Galileo system of the European Union.
[0151] The power supply 709 is used to power the various components in the device 700. The power supply 709 can be an alternating current, a direct current, a disposable battery, or a rechargeable battery. When the power supply 709 includes a rechargeable battery, the rechargeable battery can support wired charging or wireless charging. The rechargeable battery can also support fast charging technology.
[0152] In some embodiments, the device 700 further includes one or more sensors 710 , including but not limited to: an acceleration sensor 711 , a gyroscope sensor 712 , a pressure sensor 713 , a fingerprint sensor 714 , an optical sensor 715 , and a proximity sensor 716 .
[0153] The acceleration sensor 711 can detect the magnitude of acceleration on the three coordinate axes of the coordinate system established by the device 700. For example, the acceleration sensor 711 can be used to detect the components of gravity acceleration on the three coordinate axes. The processor 701 can control the touch display screen 705 to display the user interface in a horizontal view or a vertical view according to the gravity acceleration signal collected by the acceleration sensor 711. The acceleration sensor 711 can also be used for collecting game or user motion data.
[0154] The gyro sensor 712 can detect the body direction and rotation angle of the device 700, and the gyro sensor 712 can cooperate with the acceleration sensor 711 to collect the user's 3D actions on the device 700. The processor 701 can implement the following functions based on the data collected by the gyro sensor 712: motion sensing (such as changing the UI according to the user's tilt operation), image stabilization during shooting, game control, and inertial navigation.
[0155] The pressure sensor 713 can be set on the side frame of the device 700 and / or the lower layer of the touch display screen 705. When the pressure sensor 713 is set on the side frame of the device 700, it can detect the user's holding signal of the device 700, and the processor 701 performs left and right hand recognition or shortcut operation according to the holding signal collected by the pressure sensor 713. When the pressure sensor 713 is set on the lower layer of the touch display screen 705, the processor 701 controls the operability controls on the UI interface according to the user's pressure operation on the touch display screen 705. The operability controls include at least one of a button control, a scroll bar control, an icon control, and a menu control.
[0156] The fingerprint sensor 714 is used to collect the user's fingerprint, and the processor 701 identifies the user's identity based on the fingerprint collected by the fingerprint sensor 714, or the fingerprint sensor 714 identifies the user's identity based on the collected fingerprint. When the user's identity is identified as a trusted identity, the processor 701 authorizes the user to perform relevant sensitive operations, which include unlocking the screen, viewing encrypted information, downloading software, paying, and changing settings. The fingerprint sensor 714 can be set on the front, back, or side of the device 700. When a physical button or a manufacturer logo is set on the device 700, the fingerprint sensor 714 can be integrated with the physical button or the manufacturer logo.
[0157] The optical sensor 715 is used to collect the ambient light intensity. In one embodiment, the processor 701 can control the display brightness of the touch display screen 705 according to the ambient light intensity collected by the optical sensor 715. Specifically, when the ambient light intensity is high, the display brightness of the touch display screen 705 is increased; when the ambient light intensity is low, the display brightness of the touch display screen 705 is reduced. In another embodiment, the processor 701 can also dynamically adjust the shooting parameters of the camera assembly 706 according to the ambient light intensity collected by the optical sensor 715.
[0158] The proximity sensor 716, also called a distance sensor, is usually disposed on the front panel of the device 700. The proximity sensor 716 is used to collect the distance between the user and the front of the device 700. In one embodiment, when the proximity sensor 716 detects that the distance between the user and the front of the device 700 is gradually decreasing, the processor 701 controls the touch display screen 705 to switch from the screen-on state to the screen-off state; when the proximity sensor 716 detects that the distance between the user and the front of the device 700 is gradually increasing, the processor 701 controls the touch display screen 705 to switch from the screen-off state to the screen-on state.
[0159] Those skilled in the art will appreciate that the above structure does not limit the device 700 , and the device 700 may include more or fewer components than shown in the figure, or combine certain components, or adopt a different arrangement of components.
[0160] Figure 8 800 is a structural diagram of another device for generating Cookies according to an exemplary embodiment. For example, the device 800 may be provided as a server. Figure 8 , the apparatus 800 includes a processing component 801, which further includes one or more processors, and a memory resource represented by a memory 802 for storing instructions executable by the processing component 801, such as an application. The application stored in the memory 802 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 801 is configured to execute instructions to perform the above-mentioned method of generating a cookie.
[0161] The device 800 may further include a power supply component 803 configured to perform power management of the device 801, a wired or wireless network interface 804 configured to connect the device 800 to a network, and an input-output interface 805. The device 800 may operate based on an operating system stored in the memory 802, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD or the like.
[0162] In addition, the embodiment of the present application also provides a non-temporary computer-readable storage medium, when the instructions in the storage medium are executed by the processor of the electronic device, the electronic device can perform the steps of the method for generating Cookies provided in the embodiment of the present application. Computer-readable storage media may include, but are not limited to: portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above, but are not intended to limit the scope of protection of the present invention. In the embodiments disclosed in the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, apparatus, or device.
[0163] In addition, an embodiment of the present application further provides a computer program product. When instructions in the computer program product are executed by a processor of an electronic device, the electronic device is enabled to perform the steps of the above-mentioned method for generating Cookies.
[0164] Those skilled in the art will readily appreciate other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses or adaptations of the present invention that follow the general principles of the present invention and include common knowledge or customary techniques in the art that are not disclosed in this disclosure. The specification and examples are to be considered exemplary only, and the true scope and spirit of the present invention are indicated by the following claims.
[0165] It should be understood that the present invention is not limited to the exact construction that has been described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.
Claims
1. A method for generating Cookies, characterized in that: include: Initiate a first thread, wherein the first thread is adapted to generate at least one candidate cookie corresponding to a preset uniform resource locator; In response to the first thread generating the candidate Cookie, locking the first thread so that the first thread stops generating the candidate Cookie, and starting the second thread to obtain a reference Cookie corresponding to the uniform resource locator, wherein the reference Cookie is used to verify the candidate Cookie; In response to the second thread acquiring the reference Cookie, the first thread is unlocked to enable the first thread to continue to generate a next candidate Cookie.
2. The method according to claim 1, characterized in that In response to the first thread generating the candidate cookie, locking the first thread so that the first thread stops generating the candidate cookie, and starting the second thread to obtain the reference cookie corresponding to the uniform resource locator includes: In response to the first thread generating the candidate cookie, locking the first thread so that the first thread stops generating the candidate cookie, and checking the uniform resource locator; In response to the uniform resource locator passing the check, the second thread is initiated to obtain a reference Cookie corresponding to the uniform resource locator.
3. The method according to claim 1, characterized in that The starting of the second thread to obtain the reference Cookie corresponding to the uniform resource locator comprises: Start the second thread to obtain the local cookie set from the local cookie database; The local cookie in the local cookie set and corresponding to the uniform resource locator is determined as the reference cookie.
4. The method according to claim 3, characterized in that The method further includes: starting a third thread, wherein the third thread is adapted to access the local cookie database; The starting of the second thread to obtain the local Cookie set from the local Cookie database includes: The local cookie set obtained by the third thread from the local cookie database is provided to the second thread.
5. The method according to claim 3, characterized in that: The method also includes: verifying the candidate Cookie using the benchmark Cookie.
6. The method according to claim 5, characterized in that The use of the reference Cookie to verify the candidate Cookie includes: If the candidate Cookie does not include the security attribute and the reference Cookie includes the security attribute, determining that the candidate Cookie does not pass the verification; In the case that the candidate Cookie does not contain a valid time attribute and the reference Cookie contains a valid time attribute, it is determined that the candidate Cookie does not pass the verification.
7. The method according to claim 5 or 6, characterized in that: The method further includes: In response to successfully verifying the candidate cookie using the benchmark cookie, the candidate cookie is saved to the set of planted cookies in the memory.
8. The method according to claim 7, characterized in that The method further includes: In response to a determination operation for a target uniform resource locator, extracting a cookie corresponding to the target uniform resource locator from the planted cookie set; The cookie corresponding to the target uniform resource locator is determined as a standby cookie of the target uniform resource locator.
9. A device for generating Cookies, characterized in that: include: A first starting module is configured to start a first thread, wherein the first thread is adapted to generate at least one candidate Cookie corresponding to a preset uniform resource locator; a locking module, configured to, in response to the first thread generating the candidate Cookie, lock the first thread so that the first thread stops generating the candidate Cookie, and start a second thread to obtain a reference Cookie corresponding to the uniform resource locator, wherein the reference Cookie is used to verify the candidate Cookie; The unlocking module is configured to unlock the first thread in response to the second thread acquiring the reference Cookie so that the first thread continues to generate the next candidate Cookie.
10. The device according to claim 9, characterized in that The locking module is configured to, in response to the first thread generating the candidate cookie, lock the first thread so that the first thread stops generating the candidate cookie and checks the uniform resource locator; in response to the uniform resource locator passing the check, start the second thread to obtain a reference cookie corresponding to the uniform resource locator.
11. The device according to claim 9, characterized in that The locking module is configured to start the second thread to obtain a local Cookie set from a local Cookie database; and determine the local Cookie in the local Cookie set that corresponds to the Uniform Resource Locator as the reference Cookie.
12. The device according to claim 11, characterized in that The locking module is configured to start a third thread, where the third thread is adapted to access the local Cookie database; and provide the local Cookie set obtained by the third thread from the local Cookie database to the second thread.
13. The device according to claim 11, characterized in that Also includes: The verification module is configured to verify the candidate Cookie using the benchmark Cookie.
14. The device according to claim 13, characterized in that The verification module is configured to determine that the candidate cookie fails the verification when the candidate cookie does not contain a security attribute and the benchmark cookie contains a security attribute; and to determine that the candidate cookie fails the verification when the candidate cookie does not contain a valid time attribute and the benchmark cookie contains a valid time attribute.
15. The device according to claim 13 or 14, characterized in that The verification module is configured to save the candidate cookie into the set of planted cookies in the memory in response to successfully verifying the candidate cookie using the benchmark cookie.
16. The device according to claim 15, characterized in that Also includes: The determination module is configured to extract the cookie corresponding to the target uniform resource locator from the planted cookie set in response to a determination operation on the target uniform resource locator; and determine the cookie corresponding to the target uniform resource locator as a standby cookie for the target uniform resource locator.
17. An electronic device, characterized in that: The electronic device includes: processor; a memory for storing instructions executable by the processor; The processor is used to read the executable instructions from the memory and execute the instructions to implement the method for generating Cookies as described in any one of claims 1-8.
18. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the instructions are executed by the processor, the method for generating Cookies described in any one of claims 1-8 is implemented.
