CN106453573A - Method and system for processing CGI request in HTTP server - Google Patents

Method and system for processing CGI request in HTTP server Download PDF

Info

Publication number
CN106453573A
CN106453573A CN201610915965.2A CN201610915965A CN106453573A CN 106453573 A CN106453573 A CN 106453573A CN 201610915965 A CN201610915965 A CN 201610915965A CN 106453573 A CN106453573 A CN 106453573A
Authority
CN
China
Prior art keywords
request
cgi
processing function
processing
name
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201610915965.2A
Other languages
Chinese (zh)
Inventor
丁森林
姚毅
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Lingyun Tianbo Photoelectric Technology Co Ltd
Original Assignee
Lingyun Tianbo Photoelectric Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Lingyun Tianbo Photoelectric Technology Co Ltd filed Critical Lingyun Tianbo Photoelectric Technology Co Ltd
Priority to CN201610915965.2A priority Critical patent/CN106453573A/en
Publication of CN106453573A publication Critical patent/CN106453573A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/34Network arrangements or protocols for supporting network services or applications involving the movement of software or configuration parameters 
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/50Reducing energy consumption in communication networks in wire-line communication networks, e.g. low power modes or reduced link rate

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

The invention provides a method and system for processing a CGI request in an HTTP server. The method for processing the CGI request in the HTTP server comprises the following steps: generating a processing function information table in the HTTP server in advance; receiving an HTTP request sent by a client browser; judging whether the HTTP request is the CGI request; if the HTTP request is the CGI request, extracting a request name of the CGI request, and calling a CGI processing function corresponding to the request name according to a corresponding relationship of the request name and the CGI processing function in the processing function information table; and using the called CGI processing function to process the CGI request to obtain a response request corresponding to the CGI request; and sending the response request to the client browser. The technical scheme of the invention can avoid the situation that excessive hardware resources are occupied resulting from that excessive processing procedures of the CGI request are started.

Description

Method and system for processing CGI request in HTTP server
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a method and a system for processing a CGI request in an HTTP server.
Background
The embedded device can generally implement a network management manner based on HTTP (Hyper-Text Transfer Protocol). A server of an embedded device generally exists as an HTTP server responding to an HTTP request in a network management manner of a b/s (browser/server, client browser/server) architecture; the HTTP request includes a CGI (Common Gateway Interface) request for acquiring a dynamic resource in the embedded device. In the above b/s architecture, when the HTTP server determines that the HTTP request sent by the client browser is a CGI request, the HTTP server passes the CGI request to the corresponding CGI script program in the embedded device for processing.
Fig. 1 is a schematic flow chart illustrating a processing flow of a CGI request in the prior art. As shown in fig. 1, in the embedded device 1, the HTTP server 11 receives an HTTP request sent by the client browser 2, and when receiving the HTTP request sent by the client browser 2, starts a processing procedure of the HTTP request, and determines whether the HTTP request is a CGI request by analyzing the HTTP request. When determining that the HTTP request is a CGI request, the HTTP server 11 opens a processing procedure of the CGI request to call, through the CGI interface specification, the CGI script program 12 corresponding to the CGI request to process the CGI request. The CGI script program 12 determines the path of the service data requested by the CGI request, for example, when the service data is in the database 13, the service data is called from the corresponding storage location of the database 13 to the HTTP server 11 according to the path, so that the HTTP server reads the service data, and at this time, the processing procedure of the CGI request is ended. After reading the service data, the HTTP server 11 packages the service data into an HTTP response packet, and sends the HTTP response packet to the original client browser 2.
In the prior art, each time a CGI script program is called to run, a processing procedure of a CGI request is started to run. As shown in fig. 1, if a plurality of browsers respectively send CGI requests or one browser sends a plurality of CGI requests within a certain time, a process of processing a plurality of CGI requests may be started and run. The starting operation of the processing process of multiple CGI requests can occupy excessive hardware resources of the embedded device, especially for the embedded device with limited hardware resources (such as ethernet over coax EOC device). The excessive occupation of hardware resources further causes the system to be jammed, seriously and even causes the system crash of the embedded device, and the restart party is required to recover.
Disclosure of Invention
The invention aims to provide a technical scheme for processing a CGI request in an HTTP server, which aims to solve the problem that when a plurality of CGI requests are received in the prior art introduced in the background art, the processing processes of the CGI requests are often called, and excessive hardware resources of embedded equipment are occupied.
In order to solve the technical problems, the invention provides the following technical scheme:
according to a first aspect of the present invention, there is provided a processing method of a CGI request in an HTTP server, for the HTTP server, the method including:
pre-generating a processing function information table in the HTTP server, wherein the processing function information table contains a corresponding relation between a request name of a CGI request and a CGI processing function;
receiving an HTTP request sent by a client browser;
judging whether the HTTP request is a CGI request;
if the HTTP request is a CGI request, extracting a request name of the CGI request, and calling a CGI processing function corresponding to the request name of the CGI request according to the corresponding relation between the request name and the CGI processing function in the processing function information table;
processing the CGI request by using the called CGI processing function to obtain a response result corresponding to the CGI request;
and sending the response result to the client browser.
Preferably, the extracting a request name of the CGI request, and calling the CGI processing function corresponding to the request name of the CGI request according to a correspondence between the request name and the CGI processing function in the processing function information table includes:
extracting a request name of the CGI request from Uniform Resource Locator (URL) information of the CGI request;
judging whether a CGI processing function corresponding to the request name of the CGI request exists in the processing function information table;
if a CGI processing function corresponding to the request name of the CGI request exists in the processing function information table, calling the CGI processing function from a memory; or,
and if the CGI processing function corresponding to the request name of the CGI request does not exist in the processing function information table, sending a response failure message to the client browser.
Preferably, the processing the CGI request by using the called CGI processing function to obtain a response result corresponding to the CGI request includes:
determining a request mode of the CGI request according to request method information in the CGI request;
if the request mode of the CGI request is a GET request mode, analyzing URL information of the CGI request to obtain form data, and processing the form data by using the CGI processing function to obtain a corresponding response result; or,
if the request mode of the CGI request is a POST request mode, determining an entity type of a message entity in the CGI request, analyzing the message entity according to an analysis mode corresponding to the entity type to obtain form data, and processing the form data by using the CGI processing function to obtain a corresponding response result.
Preferably, the method further comprises:
if the HTTP request is a static resource request, opening a corresponding resource file according to a target path contained in the URL information of the static resource request;
if the resource file is opened successfully, reading file state information and file content of the resource file;
and sending the file state information and the file content to the client browser.
Preferably, the method further comprises:
acquiring system inter-process communication requests sent by other application programs in a system where the HTTP server is located;
calling a communication request processing function corresponding to the inter-system-process communication request according to the corresponding relation between the identity authentication Identification (ID) number of the inter-system-process communication request and the communication request processing function;
and processing the system inter-process communication request by using the called communication request processing function to obtain a response result corresponding to the system inter-process communication request.
According to a second aspect of the present invention, there is also provided a processing system of a CGI request in an HTTP server, for the HTTP server, the system including:
a generating module, configured to pre-generate a processing function information table in the HTTP server, where the processing function information table includes a correspondence between a request name of the CGI request and a CGI processing function;
the receiving module is used for receiving an HTTP request sent by a client browser;
the judging module is used for judging whether the HTTP request is a CGI request;
a calling module, configured to, if the determining module determines that the HTTP request is a CGI request, extract a request name of the CGI request, and call, according to a correspondence between the request name and a CGI processing function in the processing function information table, a CGI processing function corresponding to the request name of the CGI request;
the processing module is used for processing the CGI request by using the CGI processing function called by the calling module to obtain a response result corresponding to the CGI request;
and the sending module is used for sending the response result to the client browser.
Preferably, the retrieving module includes:
a name extraction submodule, configured to extract a request name of the CGI request from uniform resource locator URL information of the CGI request;
a function judgment submodule, configured to judge whether a CGI processing function corresponding to the request name exists in the processing function information table;
a function calling submodule, configured to, if the function determining submodule determines that the CGI processing function corresponding to the request name exists in the processing function information table, call the CGI processing function from a memory;
the sending module is further configured to send a response failure message to the client browser if the function determination submodule determines that the CGI processing function corresponding to the request name does not exist in the processing function information table.
Preferably, the processing module includes:
a request mode determining submodule, configured to determine a request mode of the CGI request according to request method information in the CGI request;
the information analysis submodule is used for analyzing the URL information of the CGI request to obtain form data if the request mode of the CGI request is a GET request mode; the first form data processing submodule is used for processing the form data by using the CGI processing function to obtain a corresponding response result; or,
an entity type determining sub-module, configured to determine an entity type of a message entity in the CGI request if the request mode of the CGI request is a POST request mode; the entity analysis submodule is used for analyzing the message entity according to an analysis mode corresponding to the entity type to obtain form data;
and the second form data processing submodule is used for processing the form data by using the CGI processing function to obtain a corresponding response result.
Preferably, the system further comprises:
the starting module is used for opening a corresponding resource file according to a target path contained in the URL information of the static resource request if the HTTP request is the static resource request;
the reading module is used for reading the file state information and the file content of the resource file if the resource file is successfully opened;
the sending module is further configured to send the file state information and the file content to the client browser.
Preferably, the receiving module is further configured to obtain a system inter-process communication request sent by another application program in a system where the HTTP server is located;
the calling module is further used for calling a communication request processing function corresponding to the inter-system-process communication request according to the corresponding relation between the identity authentication Identification (ID) number of the inter-system-process communication request and the communication request processing function;
the processing module is further configured to process the inter-system-process communication request by using the communication request processing function, and obtain a response result corresponding to the inter-system-process communication request.
Firstly, the HTTP server pre-generates a processing function information table, and the processing function information table pre-stores the corresponding relation between the request name of the CGI request and a CGI processing function; then, when determining that the received HTTP request is a CGI request, the HTTP server queries the processing function information table according to a request name of the CGI request, determines a CGI processing function corresponding to the request name from the processing function information table, and calls the CGI processing function from the memory; secondly, the HTTP server uses the CGI processing function to process the CGI request to obtain a response result corresponding to the CGI request; and finally, the HTTP server returns the response result to the client browser. In the processing scheme of the CGI request, the HTTP server generates a processing function information table in advance, and by querying the processing function information table, the HTTP server can directly call the CGI processing function from the memory to process the CGI request. Compared with the processing mode of needing to call a special CGI script program to process the CGI request in the background art, the scheme does not need to additionally start the special processing process of the CGI request, so that the excessive occupation of hardware resources by starting and running of the process is reduced, and the situations that the embedded system is jammed and even crashed and needs to be restarted due to the excessive process are further avoided.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly described below, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
FIG. 1 is a schematic flow diagram of a prior art process for CGI requests;
FIG. 2 is a diagram illustrating an application scenario according to an embodiment of the present invention;
fig. 3 is a flowchart illustrating a processing method of a CGI request in an HTTP server according to an embodiment of the present invention;
FIG. 4 is a flow chart illustrating a CGI processing function calling method in the embodiment shown in FIG. 3;
FIG. 5 is a flow chart illustrating a method of processing a CGI request in the embodiment shown in FIG. 3;
fig. 6 is a schematic structural diagram illustrating an HTTP request according to an embodiment of the present invention;
fig. 7 is a flowchart illustrating a scheduling method of a static resource request according to an embodiment of the present invention;
FIG. 8 is a flowchart illustrating a method for processing a system inter-process communication request according to an embodiment of the present invention;
fig. 9 is a schematic structural diagram illustrating a system for processing a CGI request in an HTTP server according to an embodiment of the present invention;
FIG. 10 is a block diagram of a scheduling module according to the embodiment shown in FIG. 9;
FIG. 11 is a block diagram of a processing module according to the embodiment shown in FIG. 9;
fig. 12 is a schematic structural diagram of another CGI request processing system according to an embodiment of the present invention.
Detailed Description
The processing scheme of the CGI request in the HTTP server provided by the embodiment of the invention solves the problems that when a plurality of CGI requests are received in the prior art introduced in the background art, the processing processes of the CGI requests are often called, and excessive hardware resources of embedded equipment are occupied.
In order to make the technical solutions in the embodiments of the present invention better understood and make the above objects, features and advantages of the embodiments of the present invention more comprehensible, the technical solutions in the embodiments of the present invention are described in further detail below with reference to the accompanying drawings.
Referring to fig. 2, fig. 2 is a schematic diagram of an application scenario shown in the embodiment of the present invention, as shown in fig. 2, in the application scenario, an HTTP server 11 of an embedded system 1 is used to receive an HTTP request sent by a client browser. The treatment process comprises the following steps: the HTTP server 11 receives an HTTP request sent by each client browser (the client browser 1 … … in fig. 2, client browser n), determines whether the HTTP request is a CGI request, extracts a request name of the CGI request if the HTTP request is a CGI request, queries a CGI processing function name corresponding to the request name in a processing function information table, calls the CGI processing function from a corresponding storage address in a memory according to the name of the CGI processing function, processes the CGI request using the CGI processing function, obtains a response result corresponding to each CGI request, and sends each response result back to the corresponding client browser 2. The HTTP server 11 in the embodiment of the present invention is applied to an embedded device 1, such as an EOC device (Ethernet over Coax, Ethernet over Coax based transport device).
Referring to fig. 3, fig. 3 is a flowchart illustrating a processing method of a CGI request in an HTTP server according to an embodiment of the present invention. The processing method of the CGI request in the HTTP server provided by the embodiment of the present invention is used for the HTTP server, and as shown in fig. 3, the processing method of the CGI request includes the following steps:
s110: and pre-generating a processing function information table in the HTTP server, wherein the processing function information table contains the corresponding relation between the request name of the CGI request and the CGI processing function.
By pre-generating a processing function information table in the HTTP server, when a CGI request is received, a CGI processing function corresponding to the CGI request can be obtained by directly querying the processing function information table, so that the CGI request can be further processed by calling the CGI processing function according to the CGI processing function. Since the HTTP server can directly call the CGI processing function to process the CGI request, a CGI script program except the HTTP server does not need to be called to perform special processing on the CGI request.
S120: receiving an HTTP request sent by a client browser;
s130: judging whether the HTTP request is a CGI request;
the HTTP server judges whether the HTTP request is a CGI request or not according to the URL information of the HTTP request. For example: URL ═ URL: 192.168.144.20/getMac' has "getMac" information in the URL, the HTTP request is the CGI request.
S140: and if the HTTP request is a CGI request, extracting a request name of the CGI request, and calling the CGI processing function corresponding to the request name of the CGI request according to the corresponding relation between the request name and the CGI processing function in the processing function information table.
Typically, the request name of the CGI request is generally extracted from the uniform resource locator URL information of the CGI request, for example, URL: 192.168.144.20/getMac, "getMac" is the request name.
The processing function information table specifically includes a correspondence between a request name of the CGI request and a function name of the CGI processing function, for example, a correspondence between a request name "getMac" of the CGI request and a function name "CGI _ getMac" of the CGI processing function. After the function name of the CGI processing function is found, the corresponding CGI source code file is read through the compiler according to the function name, a memory address is allocated to the source code corresponding to the CGI function, and then the corresponding CGI processing function can be called from the memory by the HTTP server.
Specifically, as shown in fig. 4, step S140 specifically includes the following steps:
s210: extracting a request name of the CGI request from Uniform Resource Locator (URL) information of the CGI request;
s220: judging whether a CGI processing function corresponding to the request name of the CGI request exists in the processing function information table or not;
s230: if a CGI processing function corresponding to the request name of the CGI request exists in the processing function information table, calling the CGI processing function from the memory address according to the CGI processing function; specifically, the specific content of the CGI processing function is read from the allocated memory address according to the function name of the CGI processing function, and the calling operation is completed. Or,
s240: and if the CGI processing function corresponding to the request name does not exist in the processing function information table, sending a response failure message to the client browser. The response failure message (e.g., the CGI processing function corresponding to the request is not found) is encapsulated in a response message and sent to the client browser, and may be specifically encapsulated in the start line of the response message.
By extracting the request name, according to the corresponding relation between the request name and the CGI processing function, the CGI processing function corresponding to the request name can be inquired from the processing function information table, and the compiler is used for allocating the memory address of the CGI processing function, so that the HTTP server can directly call the CGI processing function from the memory to process the CGI request, and the CGI request is sent to a CGI script program outside the HTTP server for processing without additionally starting a process.
S150: and processing the CGI request by using the called CGI processing function to obtain a response result corresponding to the CGI request.
S160: and sending the response result to the client browser.
The CGI request is processed by using the called CGI processing function, a response result corresponding to the CGI request is obtained and sent to the client browser, only one process is occupied, a special process is not started in addition, the CGI request is sent to the CGI script program to be processed, and therefore hardware resources (such as a CPU (Central processing Unit), an internal memory and the like) of the embedded device where the HTTP server is located can be saved.
The invention provides a processing method of a CGI request in an HTTP server, which comprises the steps that firstly, the HTTP server pre-generates a processing function information table, and the processing function information table pre-stores the corresponding relation between a request name of the CGI request and a CGI processing function; then, when determining that the received HTTP request is a CGI request, the HTTP server queries the processing function information table according to a request name of the CGI request, determines a CGI processing function corresponding to the request name from the processing function information table, and calls the CGI processing function from a memory of the HTTP server; secondly, the HTTP server uses the CGI processing function to process the CGI request to obtain a response result corresponding to the CGI request; and finally, the HTTP server returns the response result to the client browser. In the processing scheme of the CGI request, the HTTP server generates a processing function information table in advance, and by querying the processing function information table, the HTTP server can directly call the CGI processing function from the memory to process the CGI request. Compared with the processing mode of needing to call a special CGI script program to process the CGI request in the background technology, the scheme only needs the HTTP server to start one processing process, and even if a plurality of CGI requests need to be processed at the same time, the HTTP server only needs to start one process and call a CGI processing function in the HTTP server to process. The HTTP server does not need to additionally start a special processing process of the CGI request, so that excessive occupation of hardware resources caused by starting and running of the process is reduced, and the situations that the embedded equipment is jammed in the system, even the system is crashed and needs to be restarted due to excessive processes are further avoided.
As shown in fig. 5, step S150 in the embodiment shown in fig. 3: the method for processing the CGI request by using the called CGI processing function to obtain a response result corresponding to the CGI request comprises the following steps:
s310: determining a request mode of the CGI request according to request method information in the CGI request; if the request mode of the CGI request is a GET request mode, the following step S320 is executed; if the POST mode is adopted, the following step S330 is performed.
The request modes of the CGI request mainly comprise a GET mode, a POST mode, a PUT mode and a DELETE mode, wherein the GET mode and the POST mode are most commonly applied. The CGI request is essentially an HTTP request, and as shown in fig. 6, fig. 6 is a schematic structural diagram of an HTTP request according to an embodiment of the present invention. According to the specification of the HTTP protocol, the HTTP request mainly includes three parts, a start line, a message header and a message entity. The initial behavior is the first line of the HTTP message, which comprises three parts of request method information, a uniform resource locator of the request and an HTTP version. The header is additional information of the message, exists in a name/value pair list mode, and comprises information such as message content length, Cookie content, used proxy browser and the like. Where each list of name/value pairs occupies a row and has a row terminator at the end of the row. The entity part is the content to be transmitted by the HTTP, such as form data to be submitted and files to be uploaded. The request mode of the CGI is mainly determined by a request method in the start line.
S320: and analyzing the URL information of the CGI request to obtain form data, and processing the form data by using the CGI processing function to obtain a corresponding response result.
In the GET request mode, the form data is stored in the URL information, so that the form data can be obtained by analyzing the URL information of the CGI request, and a corresponding response result is obtained by processing the form data by using a CGI processing function. The situation of hardware resource consumption caused by the fact that in a traditional mode, a process needs to be started additionally and form data is processed by a CGI script program outside an HTTP server is avoided.
After obtaining the response result of the response data corresponding to the CGI request, the response data is encapsulated into the entity of the response packet, and a corresponding response status is added to the start line of the response packet, for example: the response is successful; when no response data corresponding to the CGI request is obtained or no corresponding CGI processing function is found, a corresponding response status is added to the start line of the response packet, for example: no response result corresponding to the request is found.
Or,
s330: and determining the entity type of the message entity in the CGI request, analyzing the message entity according to an analysis mode corresponding to the entity type to obtain form data, and processing the form data by using the CGI processing function to obtain a corresponding response result.
In a POST request mode, form data is stored in a message entity of a CGI request, the entity type of the message entity in the CGI request is stored in a message header of the CGI request and exists in a name-value pair mode, an HTTP server firstly receives initial line information of the CGI request, determines that the request mode of the CGI request is the POST request mode according to the initial line information, then continuously receives the message header part of the CGI request, and continuously receives the message entity after judging the entity type of the message entity according to the message header. The entity type mainly comprises an Application type and a Multipart type. In the Application type, the message entity only has basic data of a page form and does not have a file to be uploaded, and at the moment, the message entity can be directly analyzed by adopting an analysis mode corresponding to the Application type to obtain form data; if the entity type is a Multipart type, the message entity is represented to have a plurality of form data separated by separators Boundary, and uploaded files may exist; at this time, the message entity may be parsed in a parsing manner corresponding to the Multipart type, and the message entity is divided according to the delimiter Boundary to obtain form data, for example: and decoding the message entity to obtain each item name and corresponding value in the form. If the uploaded file exists, the file is directly uploaded to the HTTP server.
After the form data is processed by using the CGI processing function to obtain response data corresponding to the CGI request, the response data can be encapsulated into an entity of the response packet, and a corresponding response status is added to the start line of the response packet (for example, response is successful); when no response data corresponding to the CGI request is obtained or no corresponding CGI processing function is found, a corresponding response status is added to the start line of the response packet (for example, no corresponding request result is found).
In addition, the HTTP request includes a static resource request in addition to the CGI request for requesting the dynamic resource, and in order to obtain the static resource, as shown in fig. 7, the processing method of the CGI request in the HTTP server in the embodiment shown in fig. 3 further includes:
s410: if the HTTP request is a static resource request, opening a corresponding resource file according to a target path contained in the URL information of the static resource request;
the static resources comprise source codes such as HTML and JS, or resources such as pictures and videos. The HTTP server can determine whether the HTTP request is a static resource request or not through the Uniform Resource Locator (URL) information of the HTTP request, and can directly open a corresponding resource file through a target path in the URL information. If the HTTP server fails to open the resource file, a response result of the response failure is added to an initial line of a response packet sent to the client browser, for example, information of "no corresponding request file is found" is added to the response packet.
S420: if the resource file is opened successfully, reading file state information and file content of the resource file;
the file state information comprises file size information, read-write permission, last modification time and other file states; when the HTTP server acquires the file size information, whether the file size is 0 or not can be judged, and if the file size is 0, a response result of response failure is added to an initial line of a response message sent to the client browser.
S430: and sending the file state information and the file content to the client browser.
The file state information sent to the client browser mainly comprises file size information, wherein when the file state information and file content are packaged into a response message and sent to the client browser, a start line and a header of the response message are sent first, wherein the start line indicates a response result: the request is successful. The header of the resource file comprises information such as the type of the message entity, the length of the message entity and the like. And the message entity includes the file content.
As another embodiment of the present invention, the scheme may also receive a system inter-process communication request; as shown in fig. 8, the embodiment shown in fig. 8 includes, in addition to the method shown in fig. 3:
s510: and acquiring system inter-process communication requests sent by other application programs in the system where the HTTP server is located.
S520: and calling a communication request processing function corresponding to the system inter-process communication request from the memory according to the corresponding relation between the ID number of the system inter-process communication request and the communication request processing function.
The communication requests among the system processes can be distinguished through the ID numbers, a relation information table containing the corresponding relation between the ID numbers of the communication requests among the system processes and the communication request processing functions can be pre-generated in the HTTP server, and the communication request processing functions corresponding to the communication requests among the system processes can be inquired according to the corresponding relation between the ID numbers and the corresponding communication request processing functions, so that the HTTP server can directly call the communication request processing functions of different types from the memory to process the communication requests among the system processes. Such as: and the HTTP server receives msg information sent by the Upgrade process, and calls a corresponding processing function according to the id of the msg information to process, so that the success of system upgrading is confirmed through the msg information.
S530: and processing the communication request among the system processes by using the called communication request processing function to obtain a response result corresponding to the communication request among the system processes.
The HTTP server is added with a function of processing the system inter-process communication request, so that the HTTP server can be used as a uniform processing platform to centrally process various different types of system inter-process communication requests sent by other application programs in the system.
In the embedded device, the HTTP server can be used as a uniform processing platform to process various different types of system inter-process communication requests in a centralized manner, so that the various different types of system inter-process communication requests can be directly processed by calling a communication request processing function by the HTTP server in the processing process of the HTTP server, excessive processes are not occupied, and the consumption of hardware resources (such as a memory and a CPU) in the embedded device is reduced.
In addition, in the method provided by the embodiment of the present invention, the HTTP server may also perform user authentication on the CGI request, specifically, authentication may be performed before querying the processing function information table.
Based on the same inventive concept, the embodiment of the present application further provides a processing system for a CGI request in an HTTP server, and as the method corresponding to the system is the processing method for the CGI request in the HTTP server in the embodiment of the present application, and the principle of the system for solving the problem is similar to the method, the implementation of the system may refer to the implementation of the method, and repeated details are not repeated.
Referring to fig. 9, fig. 9 is a schematic structural diagram of a processing system for a CGI request in an HTTP server according to an embodiment of the present invention, where the processing system for a CGI request is used in the HTTP server, and the system includes:
a generating module 901, configured to pre-generate a processing function information table in the HTTP server, where the processing function information table includes a correspondence between a request name of a CGI request and a CGI processing function;
a receiving module 902, configured to receive an HTTP request sent by a client browser;
a determining module 903, configured to determine whether the HTTP request is a CGI request;
a calling module 904, configured to, if the determining module 903 determines that the HTTP request is a CGI request, extract a request name of the CGI request, and call a CGI processing function corresponding to the request name of the CGI request according to a correspondence between the request name and the CGI processing function in the processing function information table;
a processing module 905, configured to process the CGI request using the CGI processing function called by the calling module 904, to obtain a response result corresponding to the CGI request;
a sending module 906, configured to send the response result to the client browser.
The invoking module 904 shown in fig. 9 mainly performs invoking according to the request name of the CGI request, and as shown in fig. 10, the invoking module 904 includes:
a name extraction submodule 9041, configured to extract a request name of the CGI request from uniform resource locator URL information of the CGI request;
a function judgment sub-module 9042, configured to judge whether a CGI processing function corresponding to the request name exists in the processing function information table;
a function calling sub-module 9043, configured to, if the function determining sub-module 9042 determines that the CGI processing function corresponding to the request name exists in the processing function information table, call the CGI processing function from a memory;
the sending module 906 is further configured to send a response failure message to the client browser if the function determining submodule 9042 determines that the CGI processing function corresponding to the request name does not exist in the processing function information table.
In order to process the form data, which may include a large amount of form data in the CGI request, as shown in fig. 11, the processing module 905 includes:
a request mode determining submodule 9051, configured to determine a request mode of the CGI request according to request method information in the CGI request;
an information analysis submodule 9052, configured to, if the request mode of the CGI request is a GET request mode, analyze URL information of the CGI request to obtain form data;
a first form data processing sub-module 9053, configured to process the form data by using the CGI processing function, to obtain a corresponding response result;
or,
an entity type determining sub-module 9054, configured to determine an entity type of a message entity in the CGI request if the request mode of the CGI request is a POST request mode;
the entity analysis submodule 9055 is configured to analyze the message entity according to an analysis mode corresponding to the entity type to obtain form data;
and the second form data processing sub-module 9056 is configured to process the form data by using the CGI processing function, so as to obtain a corresponding response result.
In addition, the HTTP server may further process a static resource request, and as shown in fig. 12, the CGI request processing system includes, in addition to the modules shown in fig. 9:
an opening module 907, configured to open a corresponding resource file according to a target path included in URL information of the static resource request if the determining module 903 determines that the HTTP request is the static resource request;
a reading module 908, configured to read file state information and file content of the resource file if the resource file is successfully opened;
the sending module 906 is further configured to send the file state information and the file content to the client browser.
Preferably, the receiving module 902 is further configured to obtain a system inter-process communication request sent by another application program in the system where the HTTP server is located;
the invoking module 904 is further configured to invoke a processing function corresponding to the inter-system-process communication request according to a corresponding relationship between an identity authentication identifier ID number of the inter-system-process communication request and a communication request processing function;
the processing module 905 is further configured to process the inter-system-process communication request by using the processing function, and obtain a response result corresponding to the inter-system-process communication request;
the sending module 906 is further configured to send the response result to the other application program.
First, the HTTP server pre-generates a processing function information table, where the processing function information table pre-stores a correspondence between a request name of the CGI request and a CGI processing function; then, when determining that the received HTTP request is a CGI request, the HTTP server queries the processing function information table according to a request name of the CGI request, determines a CGI processing function corresponding to the request name from the processing function information table, and calls the CGI processing function from the memory; secondly, the HTTP server uses the CGI processing function to process the CGI request to obtain a response result corresponding to the CGI request; and finally, the HTTP server returns the response result to the client browser. In the processing scheme of the CGI request, the HTTP server generates a processing function information table in advance, and by querying the processing function information table, the HTTP server can directly call the CGI processing function from the memory to process the CGI request. Compared with the processing mode of needing to call a special CGI script program to process the CGI request in the background art, the scheme does not need to additionally start the special processing process of the CGI request, so that the excessive occupation of hardware resources caused by starting and running of the process is reduced, and the situations that the system of the embedded equipment is crashed and needs to be restarted due to the excessive process are further avoided.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, apparatus or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product in real time on one or more computer-usable storage media (including, but not limited to, hard disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments.
The above embodiments of the present invention do not limit the scope of the present invention. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A method for processing a CGI request in an HTTP server, the method comprising:
pre-generating a processing function information table in the HTTP server, wherein the processing function information table contains a corresponding relation between a request name of a CGI request and a CGI processing function;
receiving an HTTP request sent by a client browser;
judging whether the HTTP request is a CGI request;
if the HTTP request is a CGI request, extracting a request name of the CGI request, and calling a CGI processing function corresponding to the request name of the CGI request according to the corresponding relation between the request name and the CGI processing function in the processing function information table;
processing the CGI request by using the called CGI processing function to obtain a response result corresponding to the CGI request;
and sending the response result to the client browser.
2. The method according to claim 1, wherein said extracting a request name of the CGI request, and calling the CGI processing function corresponding to the request name of the CGI request according to a correspondence between the request name and the CGI processing function in the processing function information table, comprises:
extracting a request name of the CGI request from Uniform Resource Locator (URL) information of the CGI request;
judging whether a CGI processing function corresponding to the request name of the CGI request exists in the processing function information table;
if a CGI processing function corresponding to the request name of the CGI request exists in the processing function information table, calling the CGI processing function from a memory; or,
and if the CGI processing function corresponding to the request name of the CGI request does not exist in the processing function information table, sending a response failure message to the client browser.
3. The method according to claim 1, wherein said processing the CGI request using the invoked CGI processing function to obtain a response result corresponding to the CGI request comprises:
determining a request mode of the CGI request according to request method information in the CGI request;
if the request mode of the CGI request is a GET request mode, analyzing URL information in the CGI request to obtain form data, and processing the form data by using the CGI processing function to obtain a corresponding response result; or,
if the request mode of the CGI request is a POST request mode, determining an entity type of a message entity in the CGI request, analyzing the message entity according to an analysis mode corresponding to the entity type to obtain form data, and processing the form data by using the CGI processing function to obtain a corresponding response result.
4. The method of claim 1, further comprising:
if the HTTP request is a static resource request, opening a corresponding resource file according to a target path contained in the URL information of the static resource request;
if the resource file is opened successfully, reading file state information and file content of the resource file;
and sending the file state information and the file content to the client browser.
5. The method of claim 1, further comprising:
acquiring system inter-process communication requests sent by other application programs in a system where the HTTP server is located;
calling a communication request processing function corresponding to the inter-system-process communication request according to the corresponding relation between the identity authentication Identification (ID) number of the inter-system-process communication request and the communication request processing function;
and processing the system inter-process communication request by using the called communication request processing function to obtain a response result corresponding to the system inter-process communication request.
6. A system for processing CGI requests in an HTTP server, the system comprising:
a generating module, configured to pre-generate a processing function information table in the HTTP server, where the processing function information table includes a correspondence between a request name of the CGI request and a CGI processing function;
the receiving module is used for receiving an HTTP request sent by a client browser;
the judging module is used for judging whether the HTTP request is a CGI request;
a calling module, configured to, if the determining module determines that the HTTP request is a CGI request, extract a request name of the CGI request, and call, according to a correspondence between the request name and a CGI processing function in the processing function information table, a CGI processing function corresponding to the request name of the CGI request;
the processing module is used for processing the CGI request by using the CGI processing function called by the calling module to obtain a response result corresponding to the CGI request;
and the sending module is used for sending the response result to the client browser.
7. The system of claim 6, wherein the retrieval module comprises:
a name extraction submodule, configured to extract a request name of the CGI request from uniform resource locator URL information of the CGI request;
a function judgment submodule, configured to judge whether a CGI processing function corresponding to the request name exists in the processing function information table;
a function calling submodule, configured to, if the function determining submodule determines that the CGI processing function corresponding to the request name exists in the processing function information table, call the CGI processing function from a memory;
the sending module is further configured to send a response failure message to the client browser if the function determination submodule determines that the CGI processing function corresponding to the request name does not exist in the processing function information table.
8. The system of claim 6, wherein the processing module comprises:
a request mode determining submodule, configured to determine a request mode of the CGI request according to request method information in the CGI request;
the information analysis submodule is used for analyzing the URL information of the CGI request to obtain form data if the request mode of the CGI request is a GET request mode; the first form data processing submodule is used for processing the form data by using the CGI processing function to obtain a corresponding response result; or,
an entity type determining sub-module, configured to determine an entity type of a message entity in the CGI request if the request mode of the CGI request is a POST request mode; the entity analysis submodule is used for analyzing the message entity according to an analysis mode corresponding to the entity type to obtain form data; and the second form data processing submodule is used for processing the form data by using the CGI processing function to obtain a corresponding response result.
9. The system of claim 6, further comprising:
the starting module is used for opening a corresponding resource file according to a target path contained in the URL information of the static resource request if the HTTP request is the static resource request;
the reading module is used for reading the file state information and the file content of the resource file if the resource file is successfully opened;
the sending module is further configured to send the file state information and the file content to the client browser.
10. The system according to claim 6, wherein the receiving module is further configured to obtain a system inter-process communication request sent by another application program in a system in which the HTTP server is located;
the calling module is further used for calling a communication request processing function corresponding to the inter-system-process communication request according to the corresponding relation between the identity authentication Identification (ID) number of the inter-system-process communication request and the communication request processing function;
the processing module is further configured to process the inter-system-process communication request by using the communication request processing function, and obtain a response result corresponding to the inter-system-process communication request.
CN201610915965.2A 2016-10-20 2016-10-20 Method and system for processing CGI request in HTTP server Pending CN106453573A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610915965.2A CN106453573A (en) 2016-10-20 2016-10-20 Method and system for processing CGI request in HTTP server

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610915965.2A CN106453573A (en) 2016-10-20 2016-10-20 Method and system for processing CGI request in HTTP server

Publications (1)

Publication Number Publication Date
CN106453573A true CN106453573A (en) 2017-02-22

Family

ID=58176396

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610915965.2A Pending CN106453573A (en) 2016-10-20 2016-10-20 Method and system for processing CGI request in HTTP server

Country Status (1)

Country Link
CN (1) CN106453573A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109460416A (en) * 2018-12-12 2019-03-12 成都四方伟业软件股份有限公司 A kind of data processing method, device, electronic equipment and storage medium
CN112783626A (en) * 2021-01-21 2021-05-11 珠海亿智电子科技有限公司 Interrupt processing method and device, electronic equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103297465A (en) * 2012-02-24 2013-09-11 上海盛轩网络科技有限公司 Web page server extension method and system
CN103309728A (en) * 2012-03-12 2013-09-18 腾讯科技(深圳)有限公司 Asynchronous request processing method and equipment
CN103347038A (en) * 2013-05-30 2013-10-09 上海斐讯数据通信技术有限公司 Method of WEB server for processing http messages
CN103513986A (en) * 2013-09-16 2014-01-15 山东华辰泰尔信息科技股份有限公司 Method for using CGI technology for achieving dynamic web server in no-operation system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103297465A (en) * 2012-02-24 2013-09-11 上海盛轩网络科技有限公司 Web page server extension method and system
CN103309728A (en) * 2012-03-12 2013-09-18 腾讯科技(深圳)有限公司 Asynchronous request processing method and equipment
CN103347038A (en) * 2013-05-30 2013-10-09 上海斐讯数据通信技术有限公司 Method of WEB server for processing http messages
CN103513986A (en) * 2013-09-16 2014-01-15 山东华辰泰尔信息科技股份有限公司 Method for using CGI technology for achieving dynamic web server in no-operation system

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109460416A (en) * 2018-12-12 2019-03-12 成都四方伟业软件股份有限公司 A kind of data processing method, device, electronic equipment and storage medium
CN112783626A (en) * 2021-01-21 2021-05-11 珠海亿智电子科技有限公司 Interrupt processing method and device, electronic equipment and storage medium
CN112783626B (en) * 2021-01-21 2023-12-01 珠海亿智电子科技有限公司 Interrupt processing method, device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
US20150271202A1 (en) Method, device, and system for detecting link layer hijacking, user equipment, and analyzing server
CN110020062B (en) Customizable web crawler method and system
CN107770563B (en) A kind of barrage message treatment method and device
CN107920094B (en) Data acquisition method and device, server and network equipment
CN113039763A (en) NF service consumer restart detection using direct signaling between NFs
CN108833450B (en) Method and device for preventing server from being attacked
KR102533070B1 (en) Method for prioritizing resources based on dependency of web resources, recording medium and device for performing the method
EP3896940A1 (en) Resource description file processing, and page resource obtaining method and device
CN109067860B (en) Mobile terminal message processing method and related device
CN107315948B (en) Data calling method and device
CN103546829A (en) Method and device for processing video service
CN106453573A (en) Method and system for processing CGI request in HTTP server
CN108259416B (en) Method for detecting malicious webpage and related equipment
CN107517237B (en) Video identification method and device
CN111988644A (en) Anti-stealing-link method, device, equipment and storage medium for network video
CN113596105B (en) Content acquisition method, edge node and computer readable storage medium
US20100235360A1 (en) Synchronized relay messaging and coordinated network processing using snmp
CN115086430A (en) Interference method and device of recommendation algorithm and communication system
CN110636114B (en) Customer service access method, access system, service system and cloud platform
CN111159509B (en) Data processing method and related product
US10044728B1 (en) Endpoint segregation to prevent scripting attacks
CN113824644A (en) Method, device and equipment for identifying HTTPS (hypertext transfer protocol secure) service content
CN113067878A (en) Information acquisition method, information acquisition device, information acquisition apparatus, information acquisition medium, and program product
CN114885011B (en) Method and device for calling remoteAPP service and electronic equipment
CN114090112B (en) Method and device for loading configuration file, storage medium and electronic device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20170222