Method and system for implementing HTTP request proxy forwarding based on MySQL protocol
Patent Information
- Application Number
- CN202610461749.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-09
- Publication Date
- 2026-08-18
AI Technical Summary
[0006]本发明的目的在于提供一种基于MySQL协议实现HTTP请求代理转发的方法及系统,用于解决现有跨网域通信方案中效率低下、步骤繁琐、无法实时通信、大文件传输受限、协议限制无法突破的关键问题,实现单向隔离装置场景下跨网域的实时HTTP通信、任意大小文件流式传输、简化开发流程、降低资源占用的技术效果
1.突破协议限制,实现了跨网域HTTP通信:利用网闸允许的JDBC/MySQL协议作为传输载体,将HTTP请求编码为SQL语句完成跨网域传输,成功突破网闸的协议过滤限制,实现了隔离网域间的HTTP协议通信,解决了传统HTTP代理方案无法适配网闸场景的问题。
Smart Images

Figure CN122601232A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of network security and cross-domain communication technology, and in particular to a method and system for implementing HTTP request proxy forwarding based on the MySQL protocol. It is applied to the system docking between different security level domains in the scenario of a one-way isolation device (network gateway). Specifically, it can realize real-time HTTP communication, large file streaming transmission and direct data interaction functions across domains. Background Technology
[0002] In the field of cybersecurity, industries with high data security requirements, such as government, finance, and military, typically divide their business systems into high-security internal network domains and low-security external network domains. To achieve secure isolation and compliant data exchange between these domains, one-way isolation devices (network gateways) have become core deployment equipment and are widely used in system interconnection scenarios across security-level network domains. These devices ensure secure communication between network domains through physical isolation and strict protocol filtering mechanisms. They possess core features such as protocol restrictions (only allowing a few specific protocols such as JDBC), one-way data transmission, end-to-end security auditing, and near real-time interactive response, serving as the fundamental hardware support for cross-domain data communication.
[0003] Currently, the mainstream solutions for cross-domain system interconnection based on unidirectional isolation devices mainly consist of two modes: database intermediate table interaction and file sharing transmission. The database intermediate table interaction scheme requires the external network system to write request data into an intermediate table, the internal network system to periodically poll and process it, and the processing results are written back to a result table for the external network system to retrieve again. The file sharing transmission scheme uses shared storage media, where the external network system generates a data file for the internal network system to periodically scan and read, and the processing results are returned in file format. Both schemes rely on the network gateway's open protocol for data interaction and are conventional methods for adapting to unidirectional isolation devices in existing technologies. However, in practical engineering applications, both rely on periodic polling and an intermediate carrier (table / file) for data flow, which presents unavoidable technical drawbacks.
[0004] The shortcomings of existing cross-domain communication solutions are mainly reflected in six aspects, which can no longer meet the real-time, high-efficiency, and scalability requirements of modern business: First, they are inefficient. Multiple database read / write or file operations combined with polling mechanisms result in response delays ranging from seconds to minutes, making real-time communication impossible. Second, development and maintenance are cumbersome. Complex intermediate table structures / file storage rules need to be designed to implement logic such as polling scheduling, state management, and concurrent conflict handling, resulting in a large development workload and high maintenance costs. Third, real-time interaction capabilities are lacking. The inherent delay caused by the polling interval makes it unable to support the required... Fourth, large file transfer is limited. Database BLOB fields have size thresholds, and large files require additional sharding storage logic, which can easily cause database performance bottlenecks. Fifth, streaming transmission is not possible. Files and data need to be written to an intermediate carrier before being read, making direct streaming transmission impossible. High memory usage during large file processing can easily lead to overflow issues. Sixth, protocol limitations are difficult to overcome. Network gateways only allow a few protocols such as JDBC, and traditional HTTP proxy solutions cannot be directly applied, making it impossible to meet the needs of cross-domain HTTP communication.
[0005] Therefore, there is an urgent need for a cross-domain HTTP communication solution that can overcome the limitations of network gateway protocols, achieve real-time communication, support large file streaming transmission, and simplify development, so as to adapt to the modern business needs in the scenario of one-way isolation devices. Summary of the Invention
[0006] The purpose of this invention is to provide a method and system for HTTP request proxy forwarding based on the MySQL protocol, which solves the key problems of low efficiency, cumbersome steps, inability to communicate in real time, limited large file transfer, and inability to overcome protocol limitations in existing cross-domain communication solutions. It achieves the technical effects of real-time HTTP communication across domains, streaming of files of arbitrary size, simplified development process, and reduced resource consumption in the scenario of one-way isolation device.
[0007] To achieve the above objectives, the present invention provides the following technical solution: According to one aspect of the present invention, a method for implementing HTTP request proxy forwarding based on the MySQL protocol is provided for a network architecture including an external domain, a one-way isolation device, and an internal domain, comprising the following steps: S1: Receives HTTP requests and extracts the request method, URI, parameters, request headers, and request body information; S2: Encode the HTTP request information into an SQL statement containing a custom http_proxy() function, encode the parameters and request headers in JSON format, and carry the request body as a binary stream; S3: Transmit the SQL statement to the MySQL protocol server via the JDBC protocol and then via the MySQL protocol; S4: Intercept and parse the SQL statement, and extract the HTTP request information from it; S5: Based on the extracted request information, construct and send an HTTP request to the target server in the intranet domain, and receive the HTTP response; S6: Encode the HTTP response into a MySQL result set and return it in fragments or as a whole packet via the MySQL protocol; S7: Reads the MySQL result set and streams it into an HTTP response, which is then sent back to the requesting client.
[0008] According to an embodiment of the present invention, in step S2, PreparedStatement is used to bind SQL statement parameters, which supports both MySQL text protocol and binary protocol. The request body is transmitted in the form of a binary stream, supporting data transmission of arbitrary size.
[0009] According to one embodiment of the present invention, in step S4, the parameters of the http_proxy() function are parsed using regular expressions for text protocols, and the function parameters are extracted directly from the PreparedStatement parameter binding for binary protocols.
[0010] According to one embodiment of the present invention, the MySQL protocol server in step S4 adopts a Boss-Worker multi-threaded Reactor architecture. The Boss thread receives new connections and polls them to be allocated to the Worker thread pool. The Worker threads implement non-blocking I / O processing through an independent Selector.
[0011] According to an embodiment of the present invention, in step S6, when the response data is ≤16MB, it is transmitted through a single MySQL protocol packet; when the response data is >16MB, it is split into multiple protocol packets of up to 16MB for fragmented transmission. The fragmented transmission adopts zero-copy optimization, directly writing from the source data array to the network buffer.
[0012] According to one embodiment of the present invention, in step S7, the result set data is read block by block using the BinaryStream interface of Blob with a fixed buffer of 64KB. During the reading process, the output stream is refreshed periodically to ensure timely data transmission and avoid memory overflow.
[0013] According to one embodiment of the present invention, the one-way isolation device only opens JDBC protocol transmission permissions. By adapting the MySQL protocol to the JDBC protocol, cross-domain communication of the HTTP protocol between isolated network domains is realized, thus breaking through the protocol limitation of the one-way isolation device.
[0014] According to one embodiment of the present invention, in step S3, database connections are managed through a JDBC connection pool to achieve connection reuse and efficient scheduling, reduce the resource consumption of connection creation and destruction, and improve the efficiency of cross-domain data transmission.
[0015] According to one embodiment of the present invention, the encoded MySQL result set in step S6 includes complete HTTP response information including response status code, response header, and response body, ensuring the integrity and standardization of the response data and ensuring that the client can parse it correctly.
[0016] On the other hand, the present invention also provides a system for implementing HTTP request proxy forwarding based on the MySQL protocol. The system includes an HTTP-to-SQL encoding module and a response decoding module deployed in an external network domain, and a MySQL protocol server module, an SQL parsing module, an HTTP request forwarding module, and a response return module deployed in an internal network domain; wherein: The HTTP to SQL encoding module is used to receive HTTP requests from clients, extract complete request information, encode the request information into SQL statements containing the http_proxy() function, execute and transmit them through a JDBC connection pool; The MySQL protocol server module is used to receive SQL statements transmitted from external domains via the JDBC protocol, and to implement MySQL protocol handshake, authentication, connection load balancing and non-blocking I / O processing. The SQL parsing module is used to intercept SQL statements, detect http_proxy() function calls, parse and extract HTTP request information according to the protocol type, and pass it to the HTTP request forwarding module. The HTTP request forwarding module is used to construct a standard HTTP request based on the parsed HTTP request information, send it to the target server in the intranet domain, and receive HTTP response data. The response return module is used to encode HTTP response data into a MySQL result set, transmit it as a whole packet or in fragments according to rules, and return it to the external network domain via the MySQL protocol and a one-way isolation device. The response decoding module is used to read response data streaming from the MySQL result set, parse it, encapsulate it into a standard HTTP response, and send it back to the requesting client.
[0017] This invention provides a method and system for HTTP request proxy forwarding based on the MySQL protocol. By implementing HTTP request proxy forwarding based on the MySQL protocol, it effectively solves several technical pain points in cross-domain communication scenarios using one-way isolation devices (i.e., network gateways). Compared with existing technologies, the beneficial effects of this invention are as follows: 1. Breaking through protocol restrictions and realizing cross-domain HTTP communication: Using the JDBC / MySQL protocol allowed by the gateway as the transmission carrier, HTTP requests are encoded into SQL statements to complete cross-domain transmission, successfully breaking through the gateway's protocol filtering restrictions, realizing HTTP protocol communication between isolated domains, and solving the problem that traditional HTTP proxy solutions cannot be adapted to gateway scenarios.
[0018] 2. Real-time communication is achieved, significantly improving interaction efficiency: This invention abandons the intermediate table / file polling mechanism of traditional solutions. The entire HTTP request-response process can be completed with a single SQL execution, reducing the response latency to within 100ms. Compared with the traditional minute-level latency, the interaction efficiency is greatly improved, truly realizing real-time bidirectional data interaction between isolated network domains.
[0019] 3. Supports large file streaming, breaking through storage / memory limitations: Relying on the MySQL protocol BLOB mechanism, packet fragmentation transmission, and end-to-end streaming processing technology, it supports cross-domain upload and download of files of any size, breaking through the size limit of the database BLOB field; the entire process adopts a 64KB fixed buffer for streaming read and write, avoiding large files from being loaded into memory, reducing memory usage by more than 90%, and completely solving the memory overflow problem.
[0020] 4. Simplified development and maintenance, and reduced implementation costs: Since there is no need to design complex intermediate table structures and file storage rules, nor to implement logic such as polling scheduling, state management, and concurrent conflict handling, it can directly adapt to existing HTTP business requests, greatly reducing the workload of development; the modular architecture design is easy to integrate and maintain, and significantly reduces the development and maintenance costs of cross-domain system integration.
[0021] 5. Enables high performance and high concurrency, adaptable to high-load business scenarios: The MySQL protocol server adopts a multi-threaded Reactor architecture and non-blocking I / O design, combined with technologies such as round-robin load balancing and zero-copy optimization, which fully utilizes multi-core CPU resources and supports high-concurrency request processing; the zero-copy mechanism of fragmented transmission reduces memory copying, further improving data transmission efficiency, and can adapt to high-load cross-domain business scenarios.
[0022] 6. Strong compatibility and adaptability, non-intrusive modification of existing systems: Developed based on the standard MySQL / JDBC protocol, it does not require intrusive modification of existing one-way isolation devices and business systems, and can be directly integrated into the existing network architecture; at the same time, it supports automatic detection and parsing of MySQL text protocol and binary protocol, taking into account compatibility and transmission efficiency, and adapting to different client request scenarios. Attached Figure Description
[0023] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this invention, illustrate exemplary embodiments of the invention and are used to explain the invention, but do not constitute an undue limitation of the invention. In the drawings: Figure 1 This is a flowchart of a method for implementing HTTP request proxy forwarding based on the MySQL protocol according to an embodiment of the present invention; Figure 2 This is a schematic diagram of a system for implementing HTTP request proxy forwarding based on the MySQL protocol according to an embodiment of the present invention; Figure 3 This is a detailed breakdown diagram of the system's end-to-end architecture according to an embodiment of the present invention; Figure 4 This is a schematic diagram of the multi-threaded Reactor architecture of the MySQL protocol server according to an embodiment of the present invention; Figure 5 This is a schematic diagram of MySQL protocol packet fragmentation transmission according to an embodiment of the present invention. Detailed Implementation
[0024] To facilitate a clear description of the technical solutions in the embodiments of the present invention, the terms "first" and "second" are used to distinguish identical or similar items with essentially the same function and effect. For example, the first threshold and the second threshold are merely used to distinguish different thresholds and do not limit their order. Those skilled in the art will understand that the terms "first" and "second" do not limit the quantity or execution order, and that the terms "first" and "second" are not necessarily different.
[0025] It should be noted that in this invention, the terms "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in this invention should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.
[0026] In this invention, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one" or similar expressions refer to any combination of these items, including any combination of singular or plural items. For example, "at least one of a, b, or c" can represent: a, b, c, a combination of a and b, a combination of a and c, a combination of b and c, or a, b, and c, where a, b, and c can be single or multiple.
[0027] like Figure 1 The diagram illustrates a flowchart of a method for implementing HTTP request proxy forwarding based on the MySQL protocol. This method is applied to a network architecture that includes an external network domain (low security level), a one-way isolation device (network gateway), and an internal network domain (high security level). The network gateway only allows the JDBC protocol to pass through. The method includes the following steps: S1: Extract HTTP request information; The external domain's encoding module receives various HTTP requests (GET / POST / PUT / DELETE, etc.) initiated by the client, extracts complete core request information, including the HTTP request method, URI path, query parameters, request header fields, and request body data.
[0028] S2: HTTP request encoded as an SQL statement; The extracted request information is standardized and encoded to generate a SELECT statement containing a custom http_proxy() function. The query parameters and request headers are encoded in JSON format, and the request body is carried as a binary stream as function parameters. During the encoding process, PreparedStatement is used to bind SQL statement parameters. It is compatible with both MySQL text and binary protocols, and there is no size limit for the request body, supporting data transmission of arbitrary sizes.
[0029] S3: JDBC / MySQL protocol cross-network transmission; The encoded SQL statement is executed through the JDBC connection pool of the external network domain, and the database connection reuse and efficient scheduling are achieved by utilizing the JDBC connection pool; the SQL statement is transmitted to the MySQL protocol server deployed in the internal network domain through a one-way isolation device using the MySQL protocol as the underlying transmission protocol.
[0030] S4: Intercept and parse SQL statements; The MySQL protocol server in the intranet domain intercepts received SQL statements in real time, detects the custom function call of http_proxy(), and extracts HTTP request information based on the protocol type of the client request: for text protocols, it parses the parameters of the http_proxy() function using regular expressions; for binary protocols, it directly extracts function parameters from the parameter binding of PreparedStatement, thus achieving automatic protocol detection and adaptation.
[0031] S5: Construct and forward HTTP requests; The intranet domain's request forwarding module constructs a request conforming to the HTTP standard by constructing the complete URL of the target server in the intranet domain based on the parsed HTTP request information. After setting the request headers, request body, and other information as required, it sends the request to the target business server in the intranet domain and receives the HTTP response data returned by the target server.
[0032] S6: HTTP response encoded as a MySQL result set; The HTTP response data returned by the target server is standardized and encoded to generate a MySQL result set. The response data is stored in BLOB type, and the result set contains complete HTTP response information including response status code, response header, and response body. The transmission method is selected according to the size of the response data. When the response data is ≤16MB, it is transmitted as a single MySQL protocol packet. When the response data is >16MB, it is automatically split into multiple protocol packets with a maximum size of 16MB for transmission. The fragmented transmission adopts a zero-copy optimization strategy, directly writing the source data array to the network buffer to avoid intermediate data copying.
[0033] S7: Streams and parses the HTTP response; The encoded MySQL result set is carried by the JDBC / MySQL protocol and returned to the external network domain through a one-way isolation device. The decoding module of the external network domain reads the response data from the MySQL result set in a streaming manner, and reads it block by block through the BinaryStream interface of Blob with a fixed buffer of 64KB. During the reading process, the output stream is refreshed periodically, and the read data is parsed and encapsulated into a standard HTTP response, which is finally fed back to the client that made the request, avoiding memory overflow throughout the process.
[0034] This method utilizes the JDBC protocol transmission permissions that are only enabled by the one-way isolation device, and through deep adaptation of the MySQL protocol and the JDBC protocol, it enables cross-domain communication of the HTTP protocol between isolated network domains, thus breaking through the protocol filtering restrictions of the one-way isolation device.
[0035] like Figure 2The diagram shows a system for implementing HTTP request proxy forwarding based on the MySQL protocol. This system is used to implement the above method and includes an HTTP to SQL encoding module, a MySQL protocol server module, an SQL parsing module, an HTTP request forwarding module, a response return module, and a response decoding module.
[0036] The HTTP to SQL encoding module is deployed on an external network domain and developed based on the Spring Boot framework. Its core functions are to receive HTTP requests from clients, extract request information, encode the request information into SQL statements containing the http_proxy() function, bind parameters through PreparedStatement, and support both text and binary protocols.
[0037] The MySQL protocol server module, deployed in the intranet domain, is the core module of the system. It adopts a multi-threaded Reactor (Boss-Worker) architecture to implement a complete MySQL protocol server. Its core functions are to receive SQL statements transmitted from the external domain via the JDBC protocol, process MySQL protocol handshakes and authentication, and at the same time implement connection load balancing (round-robin allocation) and non-blocking I / O processing.
[0038] The SQL parsing module is deployed in the intranet domain and works in conjunction with the MySQL protocol server module. Its core functions are to intercept SQL statements, detect http_proxy() function calls, parse and extract HTTP request information according to the protocol type (text / binary), and pass the parsed information to the HTTP request forwarding module.
[0039] The HTTP request forwarding module is deployed in the intranet domain. Its core functions are to construct the complete URL of the target server based on the parsed HTTP request information, build a standard HTTP request, set the request header and request body, execute the HTTP request, and receive the response data from the target server.
[0040] The response return module is deployed in the intranet domain and works in conjunction with the HTTP request forwarding module. Its core functions are to encode HTTP response data into a MySQL result set, to transmit large response data in chunks (>16MB), and to return the MySQL result set to the external domain via the JDBC protocol using zero-copy optimization and streaming transmission mechanisms.
[0041] The response decoding module is deployed on the external network domain and integrated with the HTTP to SQL encoding module. Its core functions are to read BLOB type response data from the MySQL result set, stream the data with a 64KB fixed buffer, stream the data to the HTTP response and send it back to the client to avoid memory overflow.
[0042] like Figure 3 As shown, a detailed breakdown diagram of the system's end-to-end architecture is presented, fully illustrating the hierarchical structure and data interaction details of the external network domain, unidirectional isolation device, and internal network domain: The external domain (low security level) includes the external system (Client), the HTTP to SQL encoding module, and the response decoding module. It clarifies the process of extracting HTTP requests, JSON encoding, constructing SQL statements (SELECT http_proxy), and the logic of reading Blob and writing streaming response data. The intermediate layer is a one-way isolation device (network gateway), which only allows the JDBC protocol to pass through, reflecting the application scenario basis of this invention that breaks through protocol limitations; The intranet domain (high security level) includes a MySQL protocol server, SQL parsing module, HTTP request forwarding module, response return module, and intranet system (Target). It details the key aspects of SQL statement protocol parsing (Boss-Worker thread model, non-blocking I / O), http_proxy() function detection, text / binary protocol parameter extraction, complete URL construction, HTTP request execution, as well as MySQL result set encoding of response results, large file fragmentation (>16MB), streaming transmission, etc., fully covering the entire intranet process from SQL reception to response return.
[0043] like Figure 4 The diagram shows a multi-threaded Reactor architecture for the MySQL protocol server, illustrating the core thread model design of the MySQL protocol server. The top is the Boss thread, whose core function is to "Accept" new network connections and distribute them to the Worker thread pool below through a "round-robin" load balancing strategy. The Worker thread pool includes at least two Worker threads (Worker-0, Worker-1), each equipped with an independent Selector component to handle I / O events of multiple Channels (such as Channel1, Channel2, Channel3, Channel4) simultaneously. This architecture intuitively embodies the division of labor mode of "Boss thread receiving connections and Worker thread handling I / O", as well as the load balancing logic of evenly distributing connections, clearly demonstrating the core architectural foundation of the system of this invention that supports high-concurrency request processing.
[0044] Figure 5This diagram illustrates the fragmented transmission of MySQL protocol packets. Taking a 30MB response data as an example, it details the specific mechanism of large file fragmented transmission: the overall response data (30MB) is split into two core data packets, Packet 1 (16MB, the maximum limit for a single packet in the MySQL protocol) and Packet 2 (14MB), both containing a header and data. The header identifies key information such as the packet length and sequence number. An EOF Packet is appended at the end of the transmission, containing a header and an EOF marker to inform the receiving end that the data transmission has been completed. This diagram visually presents the solution to the MySQL protocol packet size limit of this invention, clarifies the fragmentation rules and transmission termination logic, and explains the core implementation method of large file cross-domain transmission.
[0045] Example 1: Real-time data query in a one-way isolation device scenario; External domain business systems need to query business data from the internal domain core database in real time. The network gateway only allows the JDBC protocol to pass through. Traditional solutions use polling of intermediate database tables, which has a delay of 10-20 seconds and cannot meet the real-time query requirements.
[0046] S101. The external client initiates an HTTP GET request, carrying query parameters, and the request address is the proxy address of the tcp2jdbc module; S102. The HTTP to SQL encoding module extracts the method, URI, query parameters, and request headers of the GET request. The request body is empty. The query parameters and request headers are encoded into JSON, and the SQL statement is constructed as follows: SELECT http_proxy('GET',' / api / query','{"id":"123"}','{"Content-Type":"application / json"}',NULL) asresponse; S103. Execute the SQL statement through the JDBC connection pool, and transmit it to the MySQL protocol server of the internal MySQL module via the network gateway using the MySQL protocol; S104, the MySQL protocol server accepts connections through the Boss thread and assigns them to the Worker thread for non-blocking parsing of SQL statements; S105 The SQL parsing module detects the http_proxy() function, extracts parameters using text protocol regular expressions, and passes them to the HTTP request forwarding module; S106 The HTTP request forwarding module concatenates the URL of the target server on the intranet (such as http: / / 192.168.106.7 / api / query), constructs a GET request, and sends it to the core database interface on the intranet. S107. The target server on the intranet returns the query results (JSON format, 200KB in size). The response module encodes the results into a MySQL result set and transmits them in a single 16MB protocol packet. S108. The result set is returned to the external TCP2JDBC module via the network gateway. The response decoding module reads the BLOB data in a streaming manner, writes it into an HTTP response, and sends it back to the external client. The entire request-response process has a latency of less than 100ms, which is 100-200 times more efficient than traditional solutions, enabling true real-time data querying.
[0047] Example 2: Uploading a 500MB large file in a one-way isolation device scenario; The external domain system needs to upload a 500MB video file to the internal domain file server. The network gateway only allows the JDBC protocol to pass through, and traditional solutions cannot achieve this due to the limitation of the database BLOB field (<64MB).
[0048] S201. The external client initiates an HTTP POST request to upload a 500MB video file in streaming mode. The request address is the proxy address of the tcp2jdbc module. S202, the HTTP to SQL encoding module extracts the method, URI, and request headers of the POST request, binds the request body to the body_blob parameter in binary stream form through PreparedStatement, constructs a parameterized SQL statement, and transmits it using the binary protocol; S203. Transmit SQL statements and binary stream data to the internal MySQL module via the network gateway through the JDBC protocol, and send long data in chunks using the COM_STMT_SEND_LONG_DATA command. S204, the MySQL protocol server receives binary stream data in a streaming manner, and the SQL parsing module extracts HTTP request information from the PreparedStatement parameter; The S205 HTTP request forwarding module forwards the 500MB video file to the intranet file server in a streaming manner, avoiding memory loading; S206. The intranet file server returns a successful upload response. The response return module encodes the response into a MySQL result set and returns it to the external network. S207: After decoding by the external TCP2JDBC module, the successful upload result will be sent back to the client. This embodiment supports uploading large files up to 500MB without discrimination. The total memory usage for streaming is only 64KB, with no memory overflow issues. Compared with traditional solutions, it breaks through the file size limit and enables cross-domain uploading of files of any size.
[0049] Example 3: Downloading a 1GB large file in a unidirectional isolation device scenario; The external domain system needs to download a 1GB database backup file from the internal domain. The network gateway only allows the JDBC protocol to pass through, and traditional solutions cannot achieve this due to memory overflow issues.
[0050] S301. An external client initiates an HTTP GET request to download a 1GB database backup file from the internal network. The request address is the proxy address of the tcp2jdbc module. The S302 HTTP to SQL encoding module encodes GET requests into SQL statements, which are then transmitted to the intranet MySQL module via the JDBC protocol. The S303 SQL parsing module extracts request information, and the HTTP request forwarding module sends a download request to the intranet file server to receive 1GB of file data in a streaming manner. S304. The response return module encodes the streamed file data into a MySQL result set. Because the data size exceeds 16MB, it is automatically split into 63 16MB packets and 1 2MB packet, and zero-copy optimized fragmentation transmission is adopted. S305, fragmented MySQL protocol packets are returned to the external tcp2jdbc module via the network gateway, and the response decoding module reads the fragmented data block by block with a 64KB buffer and writes it to the HTTP response in real time; S306: External network client streams file data and downloads a 1GB file. This embodiment supports cross-domain streaming download of 1GB large files with a total memory usage of only 64KB and no memory overflow issues. Compared with traditional solutions, it enables direct download of large files without intermediate storage.
[0051] Example 4: Real-time bidirectional interaction in a unidirectional isolation device scenario; The external domain risk control system needs to interact with the internal domain core transaction system in real time. When the external network initiates a risk control query, the internal network returns the result in real time and triggers subsequent transaction operations. The polling delay of traditional solutions cannot meet the real-time requirements.
[0052] S401. The external network risk control system initiates an HTTP POST request, carrying the transaction serial number, to request the risk control query interface of the internal core transaction system. S402. Through the encoding, transmission, parsing, and forwarding process of the present invention, the core transaction system of the intranet processes the query request in real time and returns the risk control result (whether it passes or not). S403. Based on the returned risk control result, the external network risk control system immediately initiates a second HTTP POST request to request the internal network to execute the transaction operation. S404. The system of the present invention completes the full-link forwarding again, and the core transaction system of the intranet executes the transaction in real time and returns the transaction result.
[0053] In this embodiment, the total latency of the two request-response processes is less than 200ms, enabling real-time bidirectional interaction between the external network and the internal network. Compared with the minute-level latency of traditional solutions, the real-time performance is improved by 50-600 times, meeting the business requirements of high real-time performance.
[0054] This invention is the first to design a custom function `http_proxy()` as the carrier of HTTP request information, encoding the structured information and binary data of the HTTP request into standard SQL statements, realizing the conversion from HTTP protocol to MySQL protocol, and laying the foundation for overcoming network gateway protocol restrictions. It adopts a Boss-Worker thread model, where the Boss thread accepts connections and round-robin allocates them to the Worker thread pool, and the Worker threads implement non-blocking I / O through independent Selectors, fully utilizing multi-core CPUs and supporting high-concurrency request processing. It supports automatic detection and parsing of MySQL text and binary protocols; text protocols extract parameters using regular expressions, while binary protocols directly extract parameters from `PreparedStatement`, balancing compatibility and transmission efficiency. Addressing the 16MB packet size limit of the MySQL protocol, it implements automatic fragmented transmission of large data, with zero-copy optimization in the fragmentation process to avoid copying intermediate buffers and improve transmission efficiency. Both the request and response bodies are transmitted using streaming, directly using the `InputStream` / `BinaryStream` interface, and processing data block by block using a 64KB fixed buffer, avoiding loading large files into memory and completely solving the memory overflow problem.
[0055] The method and system of this invention have been engineered and are divided into two modular projects: tcp2jdbc and MySQL. Developed using Java, they are compatible with the Spring Boot framework and support cross-platform deployment (Windows / Linux). They can be directly integrated into existing network architectures, both external and internal, without requiring large-scale modifications to existing network gateways and business systems. This invention addresses the practical pain points of cross-domain communication in unidirectional isolation device scenarios, offering performance and functionalities far exceeding traditional solutions. Development and maintenance costs are significantly reduced, making it suitable for large-scale application in government, finance, and military industries, demonstrating significant industrial practicality, economic value, and social value.
[0056] Although the invention has been described herein in conjunction with various embodiments, those skilled in the art will understand and implement other variations of the disclosed embodiments by reviewing the accompanying drawings, disclosure, and other materials. In this specification, the word "comprising" does not exclude other components or steps, and "a" or "an" does not exclude multiple components. A single processor or other unit can implement several functions listed in the specification. While certain measures are described in different embodiments, this does not mean that these measures cannot be combined to produce good results.
[0057] Although the invention has been described in conjunction with specific features and embodiments, it is obvious that various modifications and combinations can be made therein without departing from the spirit and scope of the invention. Accordingly, this specification and drawings are merely illustrative of the invention and are considered to cover any and all modifications, variations, combinations, or equivalents within the scope of the invention. Clearly, those skilled in the art can make various alterations and modifications to the invention without departing from its spirit and scope. Thus, if such modifications and modifications fall within the scope of the invention and its equivalents, the invention is also intended to include such modifications and modifications.
Claims
1. A method for implementing HTTP request proxy forwarding based on the MySQL protocol, used in a network architecture including an external domain, a one-way isolation device, and an internal domain, characterized in that, Includes the following steps: S1: Receives HTTP requests and extracts the request method, URI, parameters, request headers, and request body information; S2: Encode the HTTP request information into an SQL statement containing a custom http_proxy() function, encode the parameters and request headers in JSON format, and carry the request body as a binary stream; S3: Transmit the SQL statement to the MySQL protocol server via the JDBC protocol and then via the MySQL protocol; S4: Intercept and parse the SQL statement, and extract the HTTP request information from it; S5: Based on the extracted request information, construct and send an HTTP request to the target server in the intranet domain, and receive the HTTP response; S6: Encode the HTTP response into a MySQL result set and return it in fragments or as a whole packet via the MySQL protocol; S7: Reads the MySQL result set and streams it into an HTTP response, which is then sent back to the requesting client.
2. The method according to claim 1, characterized in that, In step S2, PreparedStatement is used to bind SQL statement parameters. It supports both MySQL text and binary protocols. The request body is transmitted in binary stream form, supporting data transmission of any size.
3. The method according to claim 2, characterized in that, In step S4, the parameters of the http_proxy() function are parsed using regular expressions for text protocols, and the function parameters are extracted directly from the PreparedStatement parameter bindings for binary protocols.
4. The method according to claim 1, characterized in that, The MySQL protocol server in step S4 adopts a Boss-Worker multi-threaded Reactor architecture. The Boss thread receives new connections and polls them to allocate them to the Worker thread pool. The Worker threads implement non-blocking I / O processing through an independent Selector.
5. The method according to claim 1, characterized in that, In step S6, when the response data is ≤16MB, it is transmitted through a single MySQL protocol packet. When the response data is >16MB, it is split into multiple protocol packets of up to 16MB for fragmented transmission. The fragmented transmission adopts zero-copy optimization, directly writing from the source data array to the network buffer.
6. The method according to claim 1, characterized in that, In step S7, the result set data is read block by block using the BinaryStream interface of Blob with a fixed buffer of 64KB. During the reading process, the output stream is refreshed periodically to ensure timely data transmission and avoid memory overflow.
7. The method according to claim 1, characterized in that, The one-way isolation device only allows JDBC protocol transmission permissions. By adapting the MySQL protocol to the JDBC protocol, it enables cross-domain communication of the HTTP protocol between isolated network domains, thus breaking through the protocol limitations of the one-way isolation device.
8. The method according to claim 1, characterized in that, In step S3, database connections are managed through a JDBC connection pool to achieve connection reuse and efficient scheduling, reduce the resource consumption of connection creation and destruction, and improve the efficiency of cross-domain data transmission.
9. The method according to claim 1, characterized in that, The encoded MySQL result set in step S6 includes complete HTTP response information such as response status code, response header, and response body, ensuring the integrity and standardization of the response data and ensuring that the client can parse it correctly.
10. A system for implementing HTTP request proxy forwarding based on the MySQL protocol, used to implement the method described in any one of claims 1 to 9, characterized in that, The system includes an HTTP-to-SQL encoding module and a response decoding module deployed on the external network domain, and a MySQL protocol server module, an SQL parsing module, an HTTP request forwarding module, and a response return module deployed on the internal network domain; wherein: The HTTP to SQL encoding module is used to receive HTTP requests from clients, extract complete request information, encode the request information into SQL statements containing the http_proxy() function, execute and transmit them through a JDBC connection pool; The MySQL protocol server module is used to receive SQL statements transmitted from external domains via the JDBC protocol, and to implement MySQL protocol handshake, authentication, connection load balancing and non-blocking I / O processing. The SQL parsing module is used to intercept SQL statements, detect http_proxy() function calls, parse and extract HTTP request information according to the protocol type, and pass it to the HTTP request forwarding module. The HTTP request forwarding module is used to construct a standard HTTP request based on the parsed HTTP request information, send it to the target server in the intranet domain, and receive HTTP response data. The response return module is used to encode HTTP response data into a MySQL result set, transmit it as a whole packet or in fragments according to rules, and return it to the external network domain via the MySQL protocol and a one-way isolation device. The response decoding module is used to read response data streaming from the MySQL result set, parse it, encapsulate it into a standard HTTP response, and send it back to the requesting client.