Module download method and device
By using address mapping configuration files to convert download addresses in the module manager and proxy server, the problem of unstable download of project dependency modules in different network environments is solved, and the smooth progress of module download and the complete download of dependency modules is achieved.
Patent Information
- Application Number
- CN202010099957.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-02-18
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2040-02-18
AI Technical Summary
After the project development is completed, when sending the project from the development side to the compiled side, the download process of dependent modules may be unstable or fail due to different network environments.
By starting the module manager and the proxy server, the preset address mapping configuration file is injected into the proxy server, and the module manager is used to send the download request for the initial download address to the proxy server. The proxy server or simulated server converts the download address according to the address mapping configuration file. Ensure that the final download address is easy to access.
It solves the problem that the initial download address is inconvenient to download, and ensures the smooth progress of module download. Especially when network access is unstable, it provides complete download support for project-dependent modules.
Smart Images

Figure CN113347218B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a module downloading method and device. Background Art
[0002] In the field of computer technology, after the project development is completed, the project developers need to send the project to the compiler for compilation. The project can only be released in the production environment after the compilation is completed. When sending the project from the development end to the compilation end, due to the large amount of data of the project's dependent modules, only the project code can be sent to the compilation end. The project's dependent modules need to be downloaded by the compilation end according to the download address provided by the development end. However, due to the different network environments of the compilation end and the development end, the above download process may be unstable or fail. Summary of the invention
[0003] In view of this, the embodiments of the present invention provide a module downloading method and device, which can solve the problem of instability or download failure that may exist when downloading a module using an initial download address.
[0004] To achieve the above objective, according to one aspect of the present invention, a module downloading method is provided.
[0005] The module download method of the embodiment of the present invention is used to download at least one dependent module of a target project; it includes: starting a module manager and a proxy server, and injecting a preset address mapping configuration file into the proxy server; wherein the address mapping configuration file includes a mapping relationship between an original address and an expected address; sending a first download request carrying an initial download address of the dependent module to the proxy server through the module manager; when the address mapping configuration file contains an original address that matches the initial download address of the dependent module: the proxy server determines the final download address of the dependent module according to the expected address corresponding to the original address, and generates a second download request carrying the final download address and sends it to the server.
[0006] Optionally, the original address matched by the initial download address of the dependent module is consistent with the previous path level of the initial download address; and the proxy server determines the final download address of the dependent module according to the expected address corresponding to the original address, including: determining the original address with the deepest path level among the original addresses matched by the initial download address of the dependent module as the optimal original address, and replacing the previous path level in the initial download address that is consistent with the optimal original address with the expected address corresponding to the optimal original address to form the final download address; the method also includes: when the address mapping configuration file does not contain the original address matched by the initial download address of the dependent module, the proxy server sends the first download request to the server.
[0007] Optionally, the module manager is NPM; the dependent module is an NPM package; the server is an NPM official repository or a mirror repository; and the initial download address of the dependent module is determined according to a dependent module version lock file of the target project.
[0008] To achieve the above objective, according to another aspect of the present invention, a module downloading method is provided.
[0009] The module download method of the embodiment of the present invention complies with the HTTPS protocol, including: starting a module manager and a proxy server, injecting a preset address mapping configuration file into the proxy server; wherein the address mapping configuration file includes a mapping relationship between an original address and an expected address; starting a simulation server through the proxy server, and the module manager sends a first download request to the simulation server via the proxy server; wherein the first download request carries the initial download address of a dependent module of a target project; using the simulation server to determine whether the address mapping configuration file contains an original address that matches the initial download address of the dependent module: if so, the simulation server determines the final download address of the dependent module based on the expected address corresponding to the original address, and generates a second download request carrying the final download address and sends it to the server.
[0010] Optionally, the method further includes: before the module manager sends the first download request: using the module manager to send a handshake message for the target domain name to the proxy server, using the simulation server to generate a simulated digital certificate corresponding to the target domain name and returning it to the module manager; after the simulated digital certificate is verified by using a pre-installed root certificate, the module manager sends a preset session key to the simulation server via the proxy server; the session key is encrypted using the public key contained in the simulated digital certificate during the sending process; the simulation server uses the private key corresponding to the public key to decrypt the encrypted session key; wherein, the first download request is encrypted using the session key during the process of being sent from the module manager to the simulation server, and the simulation server uses the session key to decrypt the encrypted first download request, and the domain name in the initial download address of the dependent module carried in the first download request is the target domain name.
[0011] Optionally, the original address matched by the initial download address of the dependent module is consistent with the previous path level of the initial download address; and the simulation server determines the final download address of the dependent module based on the expected address corresponding to the original address, including: determining the original address with the deepest path level among the original addresses matched by the initial download address of the dependent module as the optimal original address, and replacing the previous path level in the initial download address that is consistent with the optimal original address with the expected address corresponding to the optimal original address to form the final download address; the method also includes: when the address mapping configuration file does not contain the original address matched by the initial download address of the dependent module, the simulation server sends the first download request to the server.
[0012] Optionally, the method also includes: when the simulation server receives the response information returned by the server, using the session key in the simulation server to encrypt the response information, and sending the encrypted response information to the module manager through the proxy server; wherein the response information carries the module to be downloaded; the module manager uses the session key in the module manager to decrypt the received response information to obtain the module to be downloaded.
[0013] Optionally, the module manager is NPM; the dependent module is an NPM package; the server is an NPM official repository or a mirror repository; and the initial download address of the dependent module is determined according to a dependent module version lock file of the target project.
[0014] To achieve the above objective, according to yet another aspect of the present invention, a module downloading device is provided.
[0015] The module downloading device of the embodiment of the present invention is used to download at least one dependent module of a target project; it may include: a starting unit, used to start a module manager and a proxy server, and inject a preset address mapping configuration file into the proxy server; wherein the address mapping configuration file includes a mapping relationship between an original address and an expected address; a request sending unit, used to send a first download request carrying the initial download address of the dependent module to the proxy server through the module manager; an address conversion unit, used to: when the address mapping configuration file contains an original address that matches the initial download address of the dependent module: the proxy server determines the final download address of the dependent module according to the expected address corresponding to the original address, and generates a second download request carrying the final download address and sends it to the server.
[0016] To achieve the above objective, according to another aspect of the present invention, a module downloading device is provided.
[0017] The module downloading device of the embodiment of the present invention complies with the HTTPS protocol and may include: a starting unit, used to start the module manager and the proxy server, and inject a preset address mapping configuration file into the proxy server; wherein the address mapping configuration file includes a mapping relationship between the original address and the expected address; a request sending unit, used to start the simulation server through the proxy server, and the module manager sends a first download request to the simulation server via the proxy server; wherein the first download request carries the initial download address of the dependent module of the target project; an address conversion unit, used to use the simulation server to determine whether the address mapping configuration file contains an original address that matches the initial download address of the dependent module: if so, the simulation server determines the final download address of the dependent module according to the expected address corresponding to the original address, and generates a second download request carrying the final download address and sends it to the server.
[0018] To achieve the above objective, according to another aspect of the present invention, an electronic device is provided.
[0019] An electronic device of the present invention comprises: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the module downloading method provided by the present invention.
[0020] To achieve the above objective, according to yet another aspect of the present invention, a computer-readable storage medium is provided.
[0021] A computer-readable storage medium of the present invention stores a computer program, and when the program is executed by a processor, the module downloading method provided by the present invention is implemented.
[0022] According to the technical solution of the present invention, one embodiment of the above invention has the following advantages or beneficial effects: the present invention provides two module download methods, which can be applied in an environment where plain text data is transmitted and in an environment where HTTPS (Hyper Text Transfer Protocol over Secure Socket Layer) is used for data transmission. In the first method, a module manager is used to download dependent modules of a target project, and a proxy server converts the download request sent by the module manager using a preset address mapping configuration file, thereby replacing the initial download address in the download request that is not convenient for downloading with a final download address that is convenient for downloading, thereby ensuring the smooth progress of module downloading. In the second method, in addition to starting the module manager and the proxy server, a simulation server is further started to return a simulation digital certificate corresponding to the target domain name to the module manager (the target domain name is the domain name in the initial download address of the module to be downloaded), and the public key in the simulation digital certificate can be used to encrypt the session key sent by the module manager to the simulation server; after receiving the download request, the simulation server can decrypt the download request and convert the download request using the address mapping configuration file, thereby replacing the initial download address in the download request that is not convenient for downloading with a final download address that is convenient for downloading, thereby ensuring the smooth download of the module. Both of the above methods can provide complete download support for project dependency modules when the terminal device network access is unstable, while retaining the version information recording function of the dependency modules.
[0023] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0025] Figure 1 It is a schematic diagram of the main steps of the module downloading method in the first embodiment of the present invention;
[0026] Figure 2 Schematic diagram of the implementation architecture of the module downloading method in the first embodiment of the present invention;
[0027] Figure 3 It is a schematic diagram of the main steps of the module downloading method in the second embodiment of the present invention;
[0028] Figure 4 is a schematic diagram of the implementation architecture of the module downloading method in the second embodiment of the present invention;
[0029] Figure 5 It is a schematic diagram of components of a module downloading device corresponding to the method in the first embodiment of the present invention;
[0030] Figure 6 is an exemplary system architecture diagram in which embodiments of the present invention may be applied;
[0031] Figure 7 It is a schematic diagram of the structure of an electronic device used to implement the module downloading method in the embodiment of the present invention. DETAILED DESCRIPTION
[0032] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0033] In the field of computer front-end technology, after the target project is developed, the project developers need to send the target project to the compiler for compilation, and the target project can be published in the production environment only after the compilation is completed. When the target project is sent from the development end to the compilation end, since the number of dependent modules of the target project is large (up to thousands) and the amount of data is extremely large, the code of the target project can only be sent to the compilation end, and the dependent modules of the target project need the compilation end to download by itself according to the download address provided by the development end. It should be noted that the dependent module of the embodiment of the present invention refers to the modules of all levels on which the target project depends. For example, the target project depends on module a, module a depends on module b, module b depends on module c, module c depends on modules d and e, then a, b, c, d, e are all dependent modules of the target project. In practical applications, the dependent module can be an NPM package managed by a module manager such as NPM (Node Package Manager, a package manager of Node.js, Node.js is a script runtime environment).
[0034] When using NPM to develop a target project, you first need to configure the package.json file, which defines the configuration information of the target project (such as name, version, license and other metadata) and the version range of the dependent modules. When executing the npm install command, NPM can automatically download the required modules according to this file, thereby configuring the operating and development environment required for the target project. After the dependent module is installed, NPM will automatically generate a dependent module version lock file (i.e., package-lock.json file), which records the name, accurate version, download address, verification code of the dependent module recorded in package.json, and the information of the dependent modules at each level of the dependent module (such as name, accurate version, download address, etc.). The download address in this file can be the initial download address to be described below, and the verification code in this file can be a hash value used to verify the integrity and correctness of the dependent module. If you need to install the target project on another terminal device, you need to provide the dependent module version lock file to the terminal device. When executing npm install on the terminal device, if NPM finds that there is a dependency module version lock file in the target project, it will download the dependency module of the target project according to the information in the dependency module version lock file, that is, download the dependency module of the target project according to the initial download address of the dependency module in the dependency module version lock file.
[0035] In the actual application scenario, the compiling end can be used as the above-mentioned other terminal device. When the compiling end downloads the dependent module of the target project according to the dependent module version lock file of the target project, because its network environment is often different from that of the development end, problems often occur in the download process based on the initial download address in the dependent module version lock file, resulting in the inability to download some dependent modules successfully, affecting the compilation of the target project. The present invention can be applied to the above-mentioned scenario to solve the problem of downloading the dependent module of the compiling end. It can be understood that in addition to the above-mentioned scenario, the present invention can also be applied to the scenario of downloading the dependent module when any terminal device installs the target project, and can also be applied to the scenario of downloading the dependent module when developing the target project (in this scenario, the initial download address of the dependent module is determined by NPM according to package.json and the download related information pre-configured by the developer). The following will mainly be described by taking the above-mentioned scenario of downloading the dependent module at the compiling end as an example. It should be pointed out that, in the absence of conflict, the embodiments of the present invention and the technical features in the embodiments can be combined with each other.
[0036] The present invention can be applied in an environment where plain text data is transmitted and in an environment where HTTPS protocol is used for data transmission, and is described in detail below through two embodiments. Figure 1 is a schematic diagram of the main steps of the module downloading method in the first embodiment of the present invention, Figure 2Schematic diagram of the implementation architecture of the module download method in the first embodiment of the present invention. Figure 1 , 2 As shown, the specific execution steps of the module download method of this embodiment are as follows:
[0037] Step S101: Start the module manager and the proxy server, and inject a preset address mapping configuration file into the proxy server; wherein the address mapping configuration file includes a mapping relationship between the original address of the module and the expected address.
[0038] In this step, when the client executes the download command, the client reads a predetermined address mapping configuration file, starts the proxy server, and injects the address configuration mapping file into the proxy server. Next, the client starts a module manager such as NPM, and sets the above-mentioned proxy server as an agent for executing the download in the module manager. Among them, the above-mentioned client refers to an application installed on a terminal device (for example, an application for project development or compilation), which generally corresponds to an independent process. Both the proxy server and the module manager can be applications installed on the above-mentioned terminal device (i.e., the terminal device where the client is installed), and the two can correspond to an independent process respectively. In specific applications, the proxy server and the module manager can also respectively adopt independent terminal devices different from the above-mentioned terminal devices. The following is an example of the client, the proxy server and the module manager being installed on the same terminal device.
[0039] The address mapping configuration file can be pre-written by the developer according to the requirements and actual environment, which includes the mapping relationship between the original address and the expected address of the module. Specifically, the original address and the expected address are both download link addresses of the dependent module. The original address is generally an address that is not convenient for downloading due to network isolation or unstable network access on the compilation side. The expected address is an address that is easy for the compilation side to access and can download the same module (i.e., the module pointed to by the corresponding original address). The above-mentioned original address and expected address can both be URLs (Uniform Resource Lo cator), and the URL can have one or more path levels. For example, if a certain original address is www.aaa.org / x / y / z (where x, y, and z all represent strings), it includes the first path level (i.e., domain name) www.aaa.org, the second path level x, the third path level y, and the fourth path level z. The depth of the original address path level is 4 (the depth corresponds to the number of path levels). The previous path level of the original address refers to the first path level or multiple consecutive path levels including the first path level. In this example, the previous path levels of the original address are: www.aaa.org, www.aaa.org / x, www.aaa.org / x / y, www.aaa.org / x / y / z.
[0040] In actual applications, the original address and the expected address can be the link address of the NPM official repository or any mirror repository, or the link address of a non-NPM resource library such as Github (a software project hosting platform). The above mapping relationship in the address mapping configuration file can be shown in the following table.
[0041] Serial number Original address Expected address 1 www.aaa.org / x / y / z www.bbb.org / r / s / z 2 www.ccc.com / l / m / n www.ddd.com / u / v / n 3 www.aaa.org www.bbb.org 4 www.aaa.org / x www.ddd.com / u / v
[0042] In the above table, r, s, l, m, n, u, and v all represent character strings. The mapping relationship in the address mapping configuration file is used to convert the initial download address in some download requests. In this embodiment, if the proxy server determines that the address mapping configuration file contains an original address that matches the initial download address in the download request (i.e., the download address carried in the download request), the final download address is determined according to the expected address corresponding to the original address, thereby realizing the conversion of the initial download address. Among them, the original address matched by the initial download address refers to the original address that is consistent with the previous path level of the initial download address. The process of determining the final download address is specifically: the proxy server determines the original address with the deepest path level (i.e., the largest depth) from the original address matched by the initial download address and uses it as the optimal original address, and uses the expected address corresponding to the optimal original address to replace the previous path level in the initial download address that is consistent with the optimal original address, thereby forming the final download address. It can be understood that if there are other contents in the initial download address in addition to the replaced content, the other contents are retained in the final download address and are in the original position. If the address mapping configuration file contains only one original address that matches the initial download address, the original address can also be considered as the original address with the deepest path level. In addition, if the proxy server determines that the address mapping configuration file does not contain an original address that matches the initial download address, the download request is not converted.
[0043] Taking the address mapping configuration file shown in the above table as an example, if the initial download address is www.ccc.com / l / m / n, the original address it matches is the original address in record 2 (i.e., the record with sequence number 2), which is consistent with the previous path level www.ccc.com / l / m / n (i.e., all the initial download addresses) in the initial download address. At this time, the original address can be determined as the optimal original address, and the expected address www.ddd.com / u / v / n corresponding to the optimal original address is used to replace the previous path level www.ccc.com / l / m / n that is consistent with the optimal original address, thereby forming the final download address www.ddd.com / u / v / n. Since there is no other content in the initial download address except the replaced content, the above retention does not need to be performed.
[0044] If the initial download address is www.aaa.org / x / y / z, the matching original addresses are the original addresses in records 1, 3, and 4. The three original addresses are respectively consistent with the following previous path levels of the initial download address: www.aaa.org / x / y / z, www.aaa.org, and www.aaa.org / x. The path level depths of the three original addresses are 4, 1, and 2, respectively. At this time, the original address with the deepest path level, that is, the original address in record 1, can be determined as the optimal original address, and the expected address www.bbb.org / r / s / z corresponding to the optimal original address is used to replace the previous path level w ww.aaa.org / x / y / z that is consistent with the optimal original address to obtain the final download address www.bbb.org / r / s / z.
[0045] If the initial download address is www.aaa.org / x / t, the matching original addresses are the original addresses in records 3 and 4. The two original addresses are respectively consistent with the following previous path levels of the initial download address: www.aaa.org and www.aaa.org / x. The path level depths of the two original addresses are 1 and 2 respectively. At this time, the original address with the deepest path level, that is, the original address in record 4, can be determined as the optimal original address, and the expected address www.ddd.com / u / v corresponding to the optimal original address can be used to replace the previous path level www.aaa.org / x that is consistent with the optimal original address. At the same time, in addition to the replaced content, there is also unreplaced content / t in the initial download address, so / t needs to be retained in the original position, so that the final download address www.ddd.com / u / v / t can be formed.
[0046] It should be noted that the original address matched by the initial download address is generally required to be exactly the same as one or more previous path levels of the initial download address. For example, taking the address mapping configuration file shown in the above table as an example, if the initial download address is www.fff.org / x / y / z, www.ccc.com or www.ccc.com / l / m / t, it is generally believed that the address mapping configuration file does not contain the original address that matches the three. At this time, the proxy server does not process the download request carrying the above initial download address.
[0047] Step S102: sending a first download request carrying an initial download address of a dependent module of a target project to a proxy server through a module manager.
[0048] In this step, the module manager can determine the initial download address of the dependent module in the form of an NPM package from the dependent module version lock file of the target project, and can determine the initial download address of the non-NPM dependent module through the relevant information of the target project. Afterwards, the module manager can generate a first download request carrying the above initial download address and send it to the proxy server.
[0049] Step S103: When the address mapping configuration file contains an original address that matches the initial download address of the dependent module: the proxy server determines the final download address of the dependent module according to the expected address corresponding to the original address, and generates a second download request carrying the final download address and sends it to the server.
[0050] In this step, the proxy server processes separately according to the difference of the initial download address in the first download request. Specifically, if the proxy server determines that the address mapping configuration file contains the original address that matches the initial download address, the final download address is formed by the aforementioned method and a second download request carrying the final download address is generated and sent to the server; if the proxy server determines that the address mapping configuration file does not contain the original address that matches the initial download address, the first download request is sent directly to the server. Exemplarily, the above-mentioned server can be an NPM official warehouse or any mirror warehouse, or a non-NPM resource library such as Github (a software project hosting platform). After receiving the download request, the server can return the requested dependent module to the proxy server, and the proxy server can send the dependent module to the module manager to complete the download of the dependent module.
[0051] In the module download method of this embodiment, the module manager is used to download the dependent modules of the target project, and the proxy server uses a preset address mapping configuration file to convert the download request sent by the module manager, thereby replacing the initial download address in the download request that is not convenient for downloading with the final download address that is convenient for downloading, thereby ensuring the smooth progress of the module download. This method can provide complete download support for the project dependent modules when the terminal device network access is unstable, while retaining the version information recording function of the dependent modules.
[0052] Figure 3 is a schematic diagram of the main steps of the module downloading method in the second embodiment of the present invention, Figure 4 FIG. 1 is a schematic diagram of the implementation architecture of the module download method in the second embodiment of the present invention. Figure 3 , 4 As shown, the module download method of this embodiment complies with the HTTPS protocol, and the data transmitted in the communication link are all encrypted data. The module download method of this embodiment can perform the following specific steps:
[0053] Step S301: Start the module manager and the proxy server, and inject a preset address mapping configuration file into the proxy server; wherein the address mapping configuration file includes a mapping relationship between an original address and an expected address.
[0054] In this step, when the client executes the download command, the client reads a predetermined address mapping configuration file, starts the proxy server, and injects the address configuration mapping file into the proxy server. Thereafter, the client starts a module manager such as NPM, and sets the above-mentioned proxy server as an agent for executing the download in the module manager. Among them, the above-mentioned client refers to an application installed on the terminal device, which generally corresponds to an independent process. Both the proxy server and the module manager can be applications installed on the above-mentioned terminal device, and the two can correspond to an independent process respectively. The specific content and usage method of the address mapping configuration file are similar to those of the first embodiment, and will not be repeated here. One of the differences between this embodiment and the first embodiment is that the conversion of the initial download address in this embodiment is performed by the simulation server to be described below, and the conversion of the initial download address in the first embodiment is performed by the proxy server.
[0055] Step S302: Start the simulation server through the proxy server, and the module manager sends a first download request to the simulation server through the proxy server; wherein the first download request carries the initial download address of the dependent module of the target project.
[0056] In an embodiment of the present invention, the timing for the proxy server to start the simulation server may be when the proxy server receives a handshake message for the target domain name sent by the module manager. As a preferred solution, when it is necessary to download the dependent modules of the target project, the module manager sends the handshake message to the proxy server; when the proxy server receives the handshake message, it starts the simulation server and generates a simulated digital certificate corresponding to the target domain name and returns it to the module manager via the proxy server.
[0057] In this step, due to the use of HTTPS protocol, the module manager needs to send a handshake message to the server through the proxy server to establish a connection, and then obtain the digital certificate returned by the server for data encryption. The module manager will also verify whether the domain name corresponding to the handshake message (i.e., the target domain name) is the same as the domain name corresponding to the digital certificate returned by the server. If the two are the same, the module manager will determine the above-mentioned server as the correct server and send a download request for the dependent module; if the two are different, the module manager will determine the above-mentioned server as a false server and end the download process. Since it is necessary to perform address conversion on some download requests in this embodiment, the domain name corresponding to the digital certificate of the real server that provides the dependent module download often does not match the domain name corresponding to the above-mentioned handshake message. Therefore, it is necessary to start a simulated server (fake server, also referred to as a fake server) to return a data certificate (hereinafter referred to as a simulated digital certificate) matching the domain name corresponding to the above-mentioned handshake message to the module manager, thereby ensuring the continuous execution of the subsequent dependent module download process. Among them, the simulated server can be started by the proxy server and can correspond to the same process as the proxy server.
[0058] Specifically, in this embodiment, the client pre-installs the root certificate provided by CA (Certificate Authority) in the system, and the root certificate is the public key of CA. When the dependent module of the target project needs to be downloaded, the module manager first sends a handshake message for the target domain name to the proxy server. After receiving the handshake message, the proxy server starts the simulation server. The simulation server uses the corresponding tool to generate a simulated digital certificate corresponding to the target domain name and returns it to the proxy server. The proxy server returns the simulated digital certificate to the module manager.
[0059] Thereafter, the module manager first uses the above-mentioned root certificate to verify the digital certificate returned by the simulation server, that is, to determine whether the above-mentioned root certificate corresponds to the private key used to encrypt the digital certificate (the private key is the private key of the CA). After the verification is passed, the module manager uses the root certificate to decrypt the digital certificate, thereby obtaining the simulation server public key contained in the digital certificate. After that, the module manager generates a random session key, and uses the simulation server public key to encrypt the session key and sends it to the simulation server (via the proxy server). The simulation server uses the private key corresponding to the above-mentioned public key (i.e., the simulation server private key) to decrypt and obtain the session key. At this point, the module manager, the proxy server and the simulation server successfully establish a connection. Thereafter, the module manager can determine the initial download address of the dependent module in the form of an NPM package from the dependent module version lock file of the target project, and can determine the initial download address of the non-NPM dependent module through the relevant information of the target project. Next, the module manager generates a first download request carrying the above-mentioned initial download address, and uses the above-mentioned session key to encrypt the first download request, and finally sends the encrypted first download request to the simulation server via the proxy server. It can be understood that the domain name in the above-mentioned initial download address is the target domain name.
[0060] Step S303: Use the simulation server to determine whether the address mapping configuration file contains an original address that matches the initial download address of the dependent module: If so, the simulation server determines the final download address of the dependent module based on the expected address corresponding to the original address, and generates a second download request carrying the final download address and sends it to the server.
[0061] In this step, the simulation server uses the session key it has to decrypt the first download request, and processes it according to the differences in the first download request. Specifically, if the simulation server determines that the address mapping configuration file (the simulation server can read the address mapping configuration file from the proxy server) contains an original address that matches the initial download address, the method described in the first embodiment is used to form the final download address and generate a second download request carrying the final download address and send it to the server; if the simulation server determines that the address mapping configuration file does not contain an original address that matches the initial download address, the first download request is sent directly to the server. It can be understood that both the first download request and the second download request need to be encrypted when transmitted to the server.
[0062] In this embodiment, the server corresponding to the first download request is the initial server, that is, the server pointed to by the initial download address, and the server corresponding to the second download request is the expected server, that is, the server associated with the expected address. After receiving the download request, the server decrypts the download request and returns a response message including the module to be downloaded to the simulation server. After receiving the response message, the simulation server encrypts the response message using the session key it owns, and sends the encrypted response message to the module manager through the proxy server. After receiving the encrypted response message, the module manager decrypts it using the session key it owns, thereby obtaining the module to be downloaded.
[0063] Through the above steps, the present invention realizes a dependent module download scheme based on the HTTPS protocol, which can ensure the reliability of data transmission while using the final download address to obtain the dependent module. In the module download method of this embodiment, in addition to starting the module manager and the proxy server, the simulation server is further started to return a simulated digital certificate corresponding to the target domain name to the module manager. The public key in the simulated digital certificate can be used to encrypt the session key sent by the module manager to the simulation server; after receiving the download request, the simulation server can decrypt the download request and convert the download request using the address mapping configuration file, thereby replacing the initial download address in the download request that is not convenient for downloading with the final download address that is convenient for downloading, thereby ensuring the smooth download of the module. This method can provide complete download support for the project dependent module when the network access of the terminal device is unstable, while retaining the version information recording function of the dependent module.
[0064] It should be noted that, for the convenience of description, the aforementioned method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the present invention is not limited by the described action sequence, and some steps can actually be performed in other sequences or simultaneously. In addition, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily necessary to implement the present invention.
[0065] In order to better implement the above-mentioned solution of the embodiment of the present invention, relevant devices for implementing the above-mentioned solution are also provided below.
[0066] See also Figure 5 As shown, the module downloading device 500 provided in the embodiment of the present invention is used to download at least one dependent module of a target project, and may include: a starting unit 501 , a request sending unit 502 , and an address conversion unit 503 .
[0067] The startup unit 501 can be used to start the module manager and the proxy server, and inject a preset address mapping configuration file into the proxy server; wherein the address mapping configuration file includes a mapping relationship between an original address and an expected address; the request sending unit 502 can be used to send a first download request carrying the initial download address of the dependent module to the proxy server through the module manager; the address conversion unit 503 can be used to: when the address mapping configuration file contains an original address that matches the initial download address of the dependent module of the target project: the proxy server determines the final download address of the dependent module based on the expected address corresponding to the original address, and generates a second download request carrying the final download address and sends it to the server.
[0068] In the implementation of the present invention, the original address matched by the initial download address of the dependent module is consistent with the previous path level of the initial download address; and the address conversion unit 503 can also be used to: determine the original address with the deepest path level in the original address matched by the initial download address of the dependent module as the optimal original address, and use the expected address corresponding to the optimal original address to replace the previous path level in the initial download address that is consistent with the optimal original address to form the final download address; when the original address matched by the initial download address of the dependent module is not contained in the address mapping configuration file, the proxy server sends the first download request to the server.
[0069] In practical applications, the module manager is NPM; the dependent module is an NPM package; the server is an NPM official repository or a mirror repository; and the initial download address of the dependent module is determined according to the dependent module version lock file of the target project.
[0070] In addition, in an embodiment of the present invention, a module downloading device using the HTTPS protocol is further provided. The module downloading device may include a starting unit, a request sending unit, and an address conversion unit.
[0071] The startup unit can be used to start the module manager and the proxy server, and inject a preset address mapping configuration file into the proxy server; wherein the address mapping configuration file includes a mapping relationship between an original address and an expected address; the request sending unit can be used to start the simulation server through the proxy server, and the module manager sends a first download request to the simulation server via the proxy server; wherein the first download request carries the initial download address of the dependent module of the target project; the address conversion unit can be used to use the simulation server to determine whether the address mapping configuration file contains an original address that matches the initial download address of the dependent module: if so, the simulation server determines the final download address of the dependent module based on the expected address corresponding to the original address, and generates a second download request carrying the final download address and sends it to the server.
[0072] In an embodiment of the present invention, the device may further include a trust establishing unit, which is used to: before the module manager sends the first download request: use the module manager to send a handshake message for the target domain name to the proxy server, use the simulation server to generate a simulation digital certificate corresponding to the target domain name and return it to the module manager; after the simulation digital certificate is verified by using a pre-installed root certificate, the module manager sends a preset session key to the simulation server via the proxy server; the session key is encrypted using the public key contained in the simulation digital certificate during the sending process; the simulation server uses the private key corresponding to the public key to decrypt the encrypted session key; wherein, the first download request is encrypted using the session key in the process of being sent from the module manager to the simulation server, and the simulation server uses the session key to decrypt the encrypted first download request, and the domain name in the initial download address of the dependent module carried in the first download request is the target domain name.
[0073] As a preferred solution, the original address matched by the initial download address of the dependent module is consistent with the previous path level of the initial download address. The address conversion unit is further used to: determine the original address with the deepest path level among the original addresses matched by the initial download address of the dependent module as the optimal original address, and use the expected address corresponding to the optimal original address to replace the previous path level consistent with the optimal original address in the initial download address to form the final download address; when the original address matched by the initial download address of the dependent module is not contained in the address mapping configuration file, the simulation server sends the first download request to the server.
[0074] Preferably, in an embodiment of the present invention, the device may further include a module to be downloaded acquisition unit, which is used to: when the simulation server receives the response information returned by the server, encrypt the response information using the session key in the simulation server, and send the encrypted response information to the module manager through the proxy server; wherein the response information carries the module to be downloaded; and the module manager decrypts the received response information using the session key in the module manager to obtain the module to be downloaded.
[0075] In addition, in an embodiment of the present invention, the module manager is NPM; the dependent module is an NPM package; the server is an NPM official warehouse or a mirror warehouse; and the initial download address of the dependent module is determined according to the dependent module version lock file of the target project.
[0076] Two module downloading devices are provided in the embodiment of the present invention, which can be applied in the environment of using plain text to transmit data and the environment of using HTTPS to transmit data. In the first device, the module manager is used to download the dependent module of the target project, and the proxy server uses the preset address mapping configuration file to convert the download request sent by the module manager, thereby replacing the initial download address in the download request that is not convenient for downloading with the final download address that is convenient for downloading, thereby ensuring the smooth progress of the module download. In the second device, in addition to starting the module manager and the proxy server, the simulation server is further started to return the simulation digital certificate corresponding to the target domain name to the module manager, and the public key in the simulation digital certificate can be used to encrypt the session key sent by the module manager to the simulation server; after receiving the download request, the simulation server can decrypt the download request and convert the download request using the address mapping configuration file, thereby replacing the initial download address in the download request that is not convenient for downloading with the final download address that is convenient for downloading, thereby ensuring the smooth download of the module. Both of the above devices can provide complete download support for the project dependent module when the network access of the terminal device is unstable, while retaining the version information recording function of the dependent module.
[0077] Figure 6 An exemplary system architecture 600 is shown to which the module downloading method or module downloading apparatus according to the embodiment of the present invention can be applied.
[0078] like Figure 6 As shown, the system architecture 600 may include terminal devices 601, 602, 603, a network 604 and a server 605 (this architecture is only an example, and the components included in the specific architecture may be adjusted according to the specific application). The network 604 is used to provide a medium for a communication link between the terminal devices 601, 602, 603 and the server 605. The network 604 may include various connection types, such as wired, wireless communication links or optical fiber cables.
[0079] The user can use the terminal devices 601, 602, 603 to interact with the server 605 through the network 604 to receive or send messages, etc. Various terminal applications can be installed on the terminal devices 601, 602, 603, such as a module download application (only an example).
[0080] The terminal devices 601 , 602 , and 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.
[0081] The server 605 may be a server that provides various services, such as an NPM warehouse (only for example) that supports module download applications operated by users using terminal devices 601, 602, and 603. The NPM warehouse may process the received module download request and feed back the processing result (such as the module requested to be downloaded - only for example) to the terminal devices 601, 602, and 603.
[0082] It should be noted that the module downloading method provided in the embodiment of the present invention is generally executed by the terminal devices 601 , 602 , 603 , and accordingly, the module downloading apparatus is generally arranged in the terminal devices 601 , 602 , 603 .
[0083] It should be understood that Figure 6 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0084] The present invention also provides an electronic device. The electronic device of the embodiment of the present invention comprises: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the module downloading method provided by the present invention.
[0085] Reference below Figure 7 , which shows a schematic diagram of the structure of a computer system 700 of an electronic device suitable for implementing an embodiment of the present invention. Figure 7 The electronic device 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.
[0086] like Figure 7 As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage part 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the computer system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0087] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed so that a computer program read therefrom is installed into the storage section 708 as needed.
[0088] In particular, according to the embodiments disclosed in the present invention, the process described in the main step diagram above can be implemented as a computer software program. For example, the embodiments of the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the main step diagram. In the above embodiment, the computer program can be downloaded and installed from the network through the communication part 709, and / or installed from the removable medium 711. When the computer program is executed by the central processing unit 701, the above functions defined in the system of the present invention are executed.
[0089] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-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 of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer 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. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer readable signal media may also be any computer readable medium other than computer readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0090] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0091] The units involved in the embodiments of the present invention may be implemented by software or hardware. The units described may also be arranged in a processor, for example, it may be described as: a processor includes a startup unit, a request sending unit and an address translation unit. The names of these units do not constitute a limitation on the units themselves in some cases, for example, the startup unit may also be described as "a unit that provides a module manager and a proxy server to the request sending unit".
[0092] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently and not be assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by the device, the steps executed by the device include: starting the module manager and the proxy server, injecting the preset address mapping configuration file into the proxy server; wherein the address mapping configuration file includes the mapping relationship between the original address and the expected address; sending a first download request carrying the initial download address of the dependent module of the target project to the proxy server through the module manager; when the address mapping configuration file contains the original address that matches the initial download address of the dependent module: the proxy server determines the final download address of the dependent module according to the expected address corresponding to the original address, and generates a second download request carrying the final download address and sends it to the server. Alternatively, start the module manager and the proxy server, and inject a preset address mapping configuration file into the proxy server; wherein the address mapping configuration file includes a mapping relationship between an original address and an expected address; start the simulation server through the proxy server, and the module manager sends a first download request to the simulation server via the proxy server; wherein the first download request carries the initial download address of the dependent module of the target project; use the simulation server to determine whether the address mapping configuration file contains an original address that matches the initial download address of the dependent module: if so, the simulation server determines the final download address of the dependent module based on the expected address corresponding to the original address, and generates a second download request carrying the final download address and sends it to the server.
[0093] Two module download methods are provided in the embodiment of the present invention, which can be applied in an environment where data is transmitted in plain text and a data transmission environment where HTTPS is used. In the first method, a module manager is used to download the dependent module of the target project, and the proxy server uses a preset address mapping configuration file to convert the download request sent by the module manager, thereby replacing the initial download address in the download request that is not convenient for downloading with a final download address that is convenient for downloading, thereby ensuring the smooth progress of the module download. In the second method, in addition to starting the module manager and the proxy server, a simulation server is further started to return a simulation digital certificate corresponding to the target domain name to the module manager, and the public key in the simulation digital certificate can be used to encrypt the session key sent by the module manager to the simulation server; after receiving the download request, the simulation server can decrypt the download request and convert the download request using the address mapping configuration file, thereby replacing the initial download address in the download request that is not convenient for downloading with a final download address that is convenient for downloading, thereby ensuring the smooth download of the module. Both of the above methods can provide complete download support for project dependent modules when the network access of the terminal device is unstable, while retaining the version information recording function of the dependent module.
[0094] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A module downloading method, used to download at least one dependent module of a target project; characterized in that: include: Starting the module manager and the proxy server, and injecting a preset address mapping configuration file into the proxy server; wherein the address mapping configuration file includes a mapping relationship between an original address and an expected address; Sending a first download request carrying an initial download address of the dependent module to a proxy server through a module manager; When the address mapping configuration file contains an original address that matches the initial download address of the dependent module: the proxy server determines the final download address of the dependent module based on the expected address corresponding to the original address, and generates a second download request carrying the final download address and sends it to the server.
2. The method according to claim 1, characterized in that The original address matched by the initial download address of the dependent module is consistent with the previous path level of the initial download address; And, the proxy server determines the final download address of the dependent module according to the expected address corresponding to the original address, including: Determine the original address with the deepest path level in the original address matched by the initial download address of the dependent module as the optimal original address, and use the expected address corresponding to the optimal original address to replace the previous path level in the initial download address that is consistent with the optimal original address to form a final download address; The method further comprises: when the address mapping configuration file does not contain an original address that matches the initial download address of the dependent module, the proxy server sends the first download request to the server.
3. The method according to claim 1 or 2, characterized in that: The module manager is NPM; The dependent module is an NPM package; The server is the NPM official repository or mirror repository; The initial download address of the dependent module is determined according to the dependent module version lock file of the target project.
4. A module download method, complying with the HTTPS protocol, characterized in that: include: Starting the module manager and the proxy server, and injecting a preset address mapping configuration file into the proxy server; wherein the address mapping configuration file includes a mapping relationship between an original address and an expected address; The simulation server is started through the proxy server, and the module manager sends a first download request to the simulation server through the proxy server; wherein the first download request carries the initial download address of the dependent module of the target project; The simulation server is used to determine whether the address mapping configuration file contains an original address that matches the initial download address of the dependent module: if so, the simulation server determines the final download address of the dependent module based on the expected address corresponding to the original address, and generates a second download request carrying the final download address and sends it to the server.
5. The method according to claim 4, characterized in that The method further comprises: before the module manager sends the first download request: Using the module manager to send a handshake message for the target domain name to the proxy server, using the simulation server to generate a simulated digital certificate corresponding to the target domain name and returning it to the module manager; After the simulated digital certificate is authenticated by using the pre-installed root certificate, the module manager sends a preset session key to the simulated server via the proxy server; the session key is encrypted using the public key included in the simulated digital certificate during the sending process; The simulated server uses the private key corresponding to the public key to decrypt the encrypted session key; Among them, the first download request is encrypted using the session key when being sent by the module manager to the simulation server, and the simulation server uses the session key to decrypt the encrypted first download request, and the domain name in the initial download address of the dependent module carried in the first download request is the target domain name.
6. The method according to claim 4, characterized in that The original address matched by the initial download address of the dependent module is consistent with the previous path level of the initial download address; And, the simulation server determines the final download address of the dependent module according to the expected address corresponding to the original address, including: Determine the original address with the deepest path level in the original address matched by the initial download address of the dependent module as the optimal original address, and use the expected address corresponding to the optimal original address to replace the previous path level in the initial download address that is consistent with the optimal original address to form a final download address; The method further includes: when the address mapping configuration file does not contain an original address that matches the initial download address of the dependent module, the simulation server sends the first download request to the server.
7. The method according to claim 5, characterized in that The method further comprises: When the simulation server receives the response information returned by the server, the response information is encrypted using the session key in the simulation server, and the encrypted response information is sent to the module manager through the proxy server; wherein the response information carries the module to be downloaded; The module manager decrypts the received response information using the session key in the module manager to obtain the module to be downloaded.
8. The method according to any one of claims 4 to 7, characterized in that: The module manager is NPM; The dependent module is an NPM package; The server is the NPM official repository or mirror repository; The initial download address of the dependent module is determined according to the dependent module version lock file of the target project.
9. A module downloading device, used to download at least one dependent module of a target project; characterized in that: include: A startup unit, used to start the module manager and the proxy server, and inject a preset address mapping configuration file into the proxy server; wherein the address mapping configuration file includes a mapping relationship between an original address and an expected address; A request sending unit, configured to send a first download request carrying an initial download address of the dependent module to a proxy server through a module manager; The address conversion unit is used to: when the address mapping configuration file contains an original address that matches the initial download address of the dependent module: the proxy server determines the final download address of the dependent module according to the expected address corresponding to the original address, and generates a second download request carrying the final download address and sends it to the server.
10. A module downloading device, complying with the HTTPS protocol, characterized in that: include: A startup unit, used to start the module manager and the proxy server, and inject a preset address mapping configuration file into the proxy server; wherein the address mapping configuration file includes a mapping relationship between an original address and an expected address; A request sending unit, used to start the simulation server through the proxy server, and the module manager sends a first download request to the simulation server through the proxy server; wherein the first download request carries an initial download address of a dependent module of the target project; The address conversion unit is used to use the simulation server to determine whether the address mapping configuration file contains an original address that matches the initial download address of the dependent module: if so, the simulation server determines the final download address of the dependent module based on the expected address corresponding to the original address, and generates a second download request carrying the final download address and sends it to the server.
11. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 8.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Detecting Application State Using a DNS-controlled Proxy
US20170111322A1
Acceleration method for handshake request in content delivery network, device and edge node
WO2019148562A1