Disclosure of Invention
The embodiment of the invention aims to provide a method, a device, a system and a computer readable storage medium for processing an http request, which can reduce the occupation of browser resources in the use process, reduce the risk of browser locking and collapse, improve the performance and improve the use experience of users.
In order to solve the above technical problems, an embodiment of the present invention provides a method for processing an http request, including:
Intercepting a currently generated http request;
judging whether the current waiting http requests have the same target http requests as the current generated http requests or not;
discarding the currently generated http request when there is the same target http request as the currently generated http request.
Optionally, the process of judging whether the target http request which is the same as the currently generated http request exists in each currently waiting http request is:
judging whether the target http request which is the same as the currently generated http request exists in each currently waiting http request in a preset waiting array.
Optionally, the method further comprises:
When the same target http request as the currently generated http request does not exist, the currently generated http request is added to the waiting array.
Optionally, the process of determining whether the target http request same as the currently generated http request exists in each currently waiting http request in the pre-established waiting array is:
acquiring a unique identifier of the currently generated http request;
Screening each currently-waiting http request stored in a preset waiting array according to the unique identifier, judging whether a target http request consistent with the unique identifier exists or not, if yes, determining that the target http request identical with the currently-generated http request exists in each currently-waiting http request, and if not, determining that the target http request identical with the currently-generated http request does not exist in each currently-waiting http request.
Optionally, after the determining whether the target http request consistent with the unique identifier exists, the method further includes:
if not, adding the http request generated currently into a waiting array.
Optionally, before discarding the currently generated http request, the method further includes:
Judging whether the time interval between the current time and the time waiting for the response of the http request released last in the array reaches the preset time length, if so, releasing the http request generated currently so that the browser responds to the http request generated currently, and if not, executing the step of discarding the http request generated currently.
Optionally, the method further comprises:
And releasing the target http request in the waiting array while releasing the currently generated http request, so that the browser responds to the target http request.
Optionally, the preset duration is 3s.
The embodiment of the invention also provides a device for processing the http request, which comprises:
the interception module is used for intercepting the http request generated currently;
The judging module is used for judging whether the target http request which is the same as the currently generated http request exists in each currently waiting http request, and if so, triggering the discarding module;
the discarding module is configured to discard the http request that is currently generated.
The embodiment of the invention also provides a system for processing the http request, which comprises:
a memory for storing a computer program;
And a processor for implementing the steps of the http request processing method as described above when executing the computer program.
The embodiment of the invention also provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, and the computer program realizes the steps of the http request processing method when being executed by a processor.
The embodiment of the invention provides a processing method, a device, a system and a computer readable storage medium of an http request, wherein the method intercepts the http request generated currently, judges whether the http requests which are currently waiting have the same target http request as the http request generated currently or not, and discards the http request generated currently when the http requests which are the same target http request as the http request generated currently exist, so that a large number of the http requests which are generated in the same time period are in a waiting state to occupy browser resources, the occupation of the browser resources is reduced, the risk of browser blocking and crashing is reduced, and the performance and the user experience are improved.
Detailed Description
The embodiment of the invention provides a method, a device, a system and a computer readable storage medium for processing an http request, which can reduce the occupation of browser resources in the use process, reduce the risk of browser locking and collapse, improve the performance and improve the use experience of users.
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Referring to fig. 1, fig. 1 is a flowchart illustrating a method for processing an http request according to an embodiment of the present invention. The method comprises the following steps:
s110, intercepting a currently generated http request;
It should be noted that, in the large-scale multi-node virtualization system, when the same request is frequently issued for synchronizing data after one batch operation, the current http request may be intercepted, instead of directly issuing the current http request. In practical application, axios request interceptor may be used to intercept the http request currently generated.
S120, judging whether the target http request which is the same as the currently generated http request exists in each currently waiting http request;
s130, when the same target http request as the current http request exists, discarding the current http request.
Specifically, after intercepting the current http request, it may be determined whether the current http request has the same target http request as the current http request in each current http request waiting, and if the current http request has the same http request, the current http request is discarded, that is, the current http request is cancelled, and the http request is not issued any more, so that occupation of browser resources is reduced.
Further, the process of determining whether the target http request same as the currently generated http request exists in each currently waiting http request may specifically be:
and judging whether the target http requests which are the same as the currently generated http requests exist in each currently waiting http request in the preset waiting array.
It should be noted that, in practical application, a waiting array may be pre-established, and the waiting http request is added to the waiting array, and after the currently generated http request is intercepted, it may be determined whether each currently waiting http request in the waiting array has the same target http request as the currently generated http request.
Specifically, the method may further include:
when the target http request which is the same as the currently generated http request does not exist in the waiting array, adding the currently generated http request into the waiting array.
That is, if there is no http request in the waiting array that is the same as the http request currently generated, the http request currently generated is stored in the waiting array to wait.
Further, the step of determining whether the target http request same as the currently generated http request exists in each currently waiting http request in the pre-established waiting array in the step S120 may specifically be:
acquiring a unique identifier of a currently generated http request;
Screening each currently-waiting http request stored in a pre-established waiting array according to the unique identifier, judging whether a target http request consistent with the unique identifier exists, and if so, determining that the same target http request as the currently-generated http request exists in each currently-waiting http request.
It should be noted that, in the embodiment of the present invention, each http request corresponds to a unique identifier, and after intercepting a currently generated http request, the unique identifier of the http request may be obtained, where the unique identifier of the http request may be uniquely determined by a uniform resource locator (URL, uniform Resource Locator) of the request, and the URL may be determined by a request address and a request method. After the unique identifier of the http request generated currently is obtained, whether the http request which is the same as the unique identifier of the http request generated currently exists in the waiting array can be further matched according to the unique identifier of each http request which is stored in the pre-established waiting array and is currently waiting, and when the http request exists, the http request which is the same as the http request generated currently exists in the waiting response is determined, and the http request generated currently does not need to be listed in the waiting array to occupy resources, so that the http request generated currently can be directly abandoned. Of course, when the http request with the same unique identifier as the currently generated http request is not matched in the waiting array, it is indicated that the request type corresponding to the currently generated http request is the first generation http request, the http request needs to be added to the waiting array to wait for response, and if the http request with the same http request is generated subsequently, the subsequently generated http request can be abandoned.
Further, before discarding the http request currently generated, the method may further include:
judging whether the time interval between the current time and the time waiting for the response of the last released http request in the array reaches the preset time length, if so, releasing the current http request so as to enable the browser to respond to the current http request, and if not, executing the step of discarding the current http request.
It should be noted that if http requests are frequently abandoned (cancelled), the http requests will not respond all the time, in order to avoid the occurrence of the phenomenon, an anti-shake policy may be designed in practical application, specifically, in the embodiment of the present invention, after determining that the target http request identical to the currently-generated http request exists in the waiting array, whether the time interval between the last-released http requests in the waiting array at the current moment reaches a preset duration (for example, 3 s) may be further determined, and when the preset duration is reached, the currently-generated http request is directly released, so that the browser responds to the http request, and when the preset duration is not reached, the step of aborting the currently-generated http request is executed again. In addition, the current http request can be released, and the target http request in the waiting array can be released, so that the browser can respond to the target http request.
According to the method, the currently generated http requests are intercepted, whether the same target http requests as the currently generated http requests exist in the currently waiting http requests or not is judged, and when the same target http requests as the currently generated http requests exist, the currently generated http requests are abandoned, so that a large number of the same http requests generated in the same time period can be effectively prevented from occupying browser resources in a waiting state, the occupation of the browser resources is reduced, the risk of the browser blocking and collapsing is reduced, and the performance and the user experience are improved.
On the basis of the foregoing embodiment, an embodiment of the present invention further provides an http request processing apparatus, with reference to fig. 2, where the apparatus includes:
an interception module 21, configured to intercept an http request that is currently generated;
The judging module 22 is configured to judge whether the target http request that is the same as the currently generated http request exists in each currently waiting http request, and if so, trigger the discarding module 23;
a discard module 23, configured to discard the http request that is currently generated.
Further, the judging module 22 includes:
The obtaining unit is used for obtaining the unique identifier of the http request generated currently;
The judging unit is used for screening each http request currently waiting and stored in the waiting array according to the unique identifier, judging whether a target http request consistent with the unique identifier exists or not, and triggering the determining unit if the target http request consistent with the unique identifier exists;
And the determining unit is used for determining that the target http requests which are the same as the currently generated http requests exist in the currently waiting http requests.
Further, the apparatus may further include:
if not, triggering an adding unit;
And the adding unit is used for adding the http request generated currently into the waiting array.
It should be noted that, the processing device for an http request in the embodiment of the present invention has the same advantages as the processing method for an http request in the above embodiment, and for a specific description of the processing method for an http request in the embodiment of the present invention, reference is made to the above embodiment, and the disclosure is not repeated herein.
On the basis of the above embodiment, the embodiment of the present invention further provides a system for processing an http request, where the system includes:
a memory for storing a computer program;
And a processor for implementing the steps of the http request processing method as described above when executing the computer program.
For example, the processor in the embodiment of the invention can be particularly used for intercepting the http request generated currently, judging whether the target http request which is the same as the http request generated currently exists in the http requests waited currently, and discarding the http request generated currently if the target http request exists.
On the basis of the above embodiment, the embodiment of the present invention further provides a computer readable storage medium, where a computer program is stored, where the computer program when executed by a processor implements the steps of the http request processing method described above.
The computer readable storage medium may include a U disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk or an optical disk, etc. various media that can store program codes.
In the present specification, each embodiment is described in a progressive manner, and each embodiment is mainly described in a different point from other embodiments, and identical and similar parts between the embodiments are all enough to refer to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section.
It should also be noted that in this specification, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises an element.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.