WO2020155483A1 - Http请求报文头的适配方法、装置和计算机设备 - Google Patents

Http请求报文头的适配方法、装置和计算机设备 Download PDF

Info

Publication number
WO2020155483A1
WO2020155483A1 PCT/CN2019/089053 CN2019089053W WO2020155483A1 WO 2020155483 A1 WO2020155483 A1 WO 2020155483A1 CN 2019089053 W CN2019089053 W CN 2019089053W WO 2020155483 A1 WO2020155483 A1 WO 2020155483A1
Authority
WO
WIPO (PCT)
Prior art keywords
header
header field
http request
preset
request message
Prior art date
Application number
PCT/CN2019/089053
Other languages
English (en)
French (fr)
Inventor
黄小军
Original Assignee
平安科技(深圳)有限公司
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 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2020155483A1 publication Critical patent/WO2020155483A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L65/00Network arrangements, protocols or services for supporting real-time applications in data packet communication
    • H04L65/40Support for services or applications

Definitions

  • This application relates to the computer field, in particular to a method, device, computer equipment and storage medium for adapting HTTP request headers.
  • the message is the data unit exchanged and transmitted in the network, and is the data exchanged between various systems, various terminals, servers and terminals.
  • the message contains the complete data information to be sent, including at least the message header and the message body (that is, the message body).
  • the request message is the message sent to the server.
  • the server's recognition of the request message is based on the request message header. If there is an error in the request message header, such as a character error or a format error, the server will not be able to recognize the request message and thus reject the request message. Among them, some errors in the request message header can be corrected, but the prior art does not have a technical solution for correcting the wrong request message header, thereby reducing unnecessary message transmission times.
  • the main purpose of this application is to provide a method, device, computer equipment, and storage medium for adapting HTTP request headers, which are designed to automatically correct incorrectly adapted request headers, thereby reducing unnecessary network overhead.
  • this application proposes a method for adapting HTTP request headers, which includes the following steps:
  • the preset similarity algorithm is used to calculate the header field name or header field value in the preset replacement list and the incorrect header field name Or the similarity of incorrect header field values, and obtaining the header field name or header field value with the largest similarity in the replacement list;
  • the maximum value of the similarity is greater than the preset similarity threshold, replace the incorrect header field name or incorrect header field value with the header field name or header with the largest similarity Part of the field value to obtain the adapted HTTP request header.
  • This application provides a device for adapting HTTP request headers, including:
  • the message receiving unit is used to receive HTTP request messages
  • the message header obtaining unit is configured to parse the HTTP request message according to the preset format of the HTTP request message to obtain the HTTP request message header;
  • the header field name and header field value acquiring unit is configured to parse the HTTP request header according to the preset HTTP request header format to obtain header field names and header field values;
  • the message header judging unit is configured to judge whether the header field name or the header field value is correct according to a preset request header inspection rule
  • the similarity calculation unit is configured to, if the header field name or header field value is incorrect, use a preset similarity algorithm to calculate the header field name or header field value in the preset replacement list and the The similarity of incorrect header field names or incorrect header field values, and obtaining the header field name or header field value with the largest similarity in the replacement list;
  • a similarity determination unit configured to determine whether the maximum value of the similarity is greater than a preset similarity threshold
  • the replacement unit is configured to replace the incorrect header field name or incorrect header field value with the header with the largest similarity if the maximum value of the similarity is greater than the preset similarity threshold. Field name or header field value to obtain the adapted HTTP request header.
  • the present application provides a computer device including a memory and a processor, the memory stores a computer program, and the processor implements the steps of any one of the foregoing methods when the computer program is executed.
  • the present application provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of any of the above methods are implemented.
  • the method, apparatus, computer equipment and storage medium for adapting the HTTP request message header of the present application obtain the header field name and the header field value by analyzing the HTTP request message header, and then determine the header field name or Whether the header field value is correct, calculate the similarity between the header field name or the header field value in the preset replacement list and the incorrect header field name or the incorrect header field value, and the incorrect The correct header field name or incorrect header field value is replaced with the header field name or header field value with the greatest degree of similarity, thereby realizing automatic correction of incorrectly adapted request headers and reducing unnecessary networks Overhead.
  • FIG. 1 is a schematic flowchart of a method for adapting an HTTP request header according to an embodiment of the application
  • FIG. 2 is a schematic block diagram of the structure of an apparatus for adapting HTTP request headers according to an embodiment of the application
  • FIG. 3 is a schematic block diagram of the structure of a computer device according to an embodiment of the application.
  • an embodiment of the present application provides a method for adapting HTTP request headers, which includes the following steps:
  • S4 Determine whether the header field name or the header field value is correct according to the preset request header inspection rule
  • header field name or the header field value is incorrect, use a preset similarity algorithm to calculate the header field name or header field value in the preset replacement list and the incorrect header The similarity of field names or incorrect header field values, and obtaining the header field name or header field value with the largest similarity in the replacement list;
  • the HTTP request message is received.
  • the message is the data unit exchanged and transmitted in the network, and is the data exchanged between various systems, various terminals, servers and terminals.
  • the message contains the complete data information to be sent, including at least the message header and the message body (that is, the message body).
  • the request message refers to the message for sending a request.
  • the HTTP request message is parsed according to the preset format of the HTTP request message to obtain the HTTP request message header.
  • the format of the HTTP request message is: request line, request header (HTTP request message header, also called HEADER) and request body.
  • the preset HTTP request message format can be set to the format of the request line, request header, and request body. Of course, it can also be set to any other format including the HTTP request message header.
  • the process of parsing the HTTP request message includes: determining the position of the HTTP request message header, and extracting the HTTP request message header from the position.
  • the HTTP request header is parsed according to the preset HTTP request header format to obtain header field names and header field values.
  • the format of the HTTP request message header is: header field name: header field value.
  • the preset HTTP request message header format is set to header field name: header field value. Of course, it can also be set to any other format including header field name and header field value.
  • the specific format of the HTTP request header is for example: Content-Type: [type]/[subtype]; parameter. Content-type is the header field name, [type]/[subtype]; parameter is the header field value.
  • the parameter can be used to specify additional information, and is preferably used to specify the charset parameter of the text encoding method. Accordingly, the HTTP request message header is parsed to obtain the header field name and the header field value.
  • step S4 it is determined whether the header field name or the header field value is correct according to the preset request header inspection rule. If there is an error in the HTTP request header, it cannot be recognized and the server cannot receive the HTTP request. Among them, some HTTP request header errors can be identified and corrected. Therefore, it is first determined whether the header field name or the header field value is correct according to the preset request header inspection rule. If the header field name or header field value is correct, the HTTP request can be directly identified without error correction; if there is an error in the header field name or header field value, it can be corrected Make corrections, and then identify the correct HTTP request after correction.
  • the preset request packet header inspection rule can be any method of inspecting the request packet header, for example, first determine whether the header field name exists in the preset table of correct header field names, and if it exists, it indicates If the header field name is correct, if it does not exist, it indicates that the header field name is wrong; then it is judged whether the name and format of the header field value conform to the preset name and format, if it matches, it is judged correct, otherwise judged mistaken.
  • the preset similarity algorithm is used to calculate the header field name or header field value in the preset replacement list and the The similarity of incorrect header field names or incorrect header field values, and obtaining the header field name or header field value with the largest similarity in the replacement list.
  • the header field name or the header field value is incorrect, that is, the HTTP request cannot be correctly identified, so it is necessary to find the correct header field name or header field value first.
  • the header field names and header field values in the HTTP request header are calculated and the header field names and headers in the replacement list are calculated.
  • the similarity of the field values can be used to find the correct header field name and header field value.
  • step S6 it is determined whether the maximum value of the similarity is greater than a preset similarity threshold. If the maximum value of the similarity is greater than the preset similarity threshold, the table is clearly in the correct header field name or header field value, so that replacement processing can be performed; otherwise, it cannot be replaced.
  • the incorrect header field name or incorrect header field value is replaced with the maximum similarity
  • the header field name or header field value of so as to obtain the adapted HTTP request header. If the similarity is greater than the preset similarity threshold, it indicates that there is a correct header field name in the preset replacement table. Accordingly, by replacing the incorrect header field name or incorrect header field value with the most similar header field name or header field value, the wrong HTTP request header can be corrected. , So that the HTTP request can be correctly identified.
  • the method of replacing the incorrect header field value includes: replacing the incorrect part in the incorrect header field value. That is, partial replacement is used to replace the incorrect header field value. This is because the header field value includes [type]/[subtype]; parameter, among which, the parameter parameter is generally not wrong, so only the wrong [type ] Or [subtype] to replace it.
  • the step S2 of parsing the HTTP request message according to the preset HTTP request message format to obtain the HTTP request message header includes:
  • S201 Determine the position of the header of the HTTP request message according to the preset format of the HTTP request message.
  • S202 Determine whether the content in the position of the HTTP request header matches a preset HTTP request header format.
  • the HTTP request message is parsed according to the preset format of the HTTP request message to obtain the HTTP request message header.
  • the preset HTTP request message format Take the preset HTTP request message format as request line, request header, and request body, where there is a first line break between the request line and the request header, and there is a blank line between the request header and the request body, for example.
  • Find the first newline character in the HTTP request message then find the first blank line, and record the position between the first newline character and the first blank line as the HTTP request message The position of the head.
  • the content in the position of the HTTP request message header matches the preset HTTP request message header format, for example, whether it has the format of Content-Type: [type]/[subtype]; parameter. If it matches, extract the content in the position of the HTTP request message header and record it as the HTTP request message header.
  • the step S3 of parsing the HTTP request header according to the preset format of the HTTP request header to obtain header field names and header field values includes:
  • S301 Determine the position of the first colon from the HTTP request header
  • the HTTP request message header is parsed according to the preset HTTP request message header format to obtain the header field name and the header field value.
  • the preset format of the HTTP request message header is header field name: header field value, for example, Content-Type: [type]/[subtype]; parameter. That is, the header field name and the header field value are separated by a colon, and there is no colon in the header field name. Therefore, intercept the content before the first colon in the HTTP request header and record it as the header field name; intercept the content after the first colon in the HTTP request header and record it as the header Field value.
  • the format of the colon is a colon in any format, preferably an English format colon.
  • the header field value includes a type part and a subtype part
  • the step S4 of judging whether the header field name or the header field value is correct according to a preset request header inspection rule include:
  • S402 Determine whether the header field name, the type part, or the subtype part exists in the preset replacement list
  • the header field value includes a type part (for example, type) and a subtype part (subtype).
  • the possible parameter part in the header field value generally does not make mistakes. Therefore, no error judgment and replacement operations are performed to save computing power. It is then judged whether the header field name, the type part, and the subtype part are in the preset replacement list, and then it can be judged whether the header field name or the header field value is correct. Wherein, the correct header field name, type part and subtype part are prestored in the replacement list.
  • a preset similarity algorithm is used to calculate the header field name or header field value in the preset replacement list and the The step S5 of describing the similarity of the incorrect header field name or incorrect header field value, and obtaining the header field name or header field value with the largest similarity in the replacement list includes:
  • A is the character frequency vector of the incorrect header field name or incorrect header field value
  • B is the character frequency vector of the header field name or header field value in the preset replacement list
  • Ai , Bi are the i-th component vector of the vectors A and B
  • n is the value of the component vector with the largest number of component vectors in the vectors A and B, and the one with the largest similarity in the replacement list is obtained Header field name or header field value.
  • the preset similarity algorithm is used to calculate the header field name or header field value in the preset replacement list and the difference The similarity of the correct header field name or the incorrect header field value, and obtain the header field name or header field value with the largest similarity in the replacement list.
  • the cosine similarity calculation method is used to calculate the header field name or header field value in the preset replacement list and the incorrect header field name or incorrect header by using a preset similarity algorithm The similarity of field values.
  • the character frequency vector of the header field name or the header field value refers to the number of occurrences of characters in the header field name or header field value.
  • the character frequency vector of start is (1,2,1,1), that is, except for t appearing twice, other characters only appear once, and the 2 in (1,2,1,1) is the character t ⁇ vector.
  • the cosine similarity formula is used to calculate the similarity between the header field name or header field value in the preset replacement list and the incorrect header field name or incorrect header field value.
  • the method includes:
  • the value of the content-type header field is set to text/html. If the maximum value of the similarity is not greater than the preset similarity threshold, it indicates that the correct header field name or header field value cannot be found. In general, it is common for the header field to be named content-type and the header field value is text/html. It is possible to correct the error of the HTTP request header. Therefore, the header field name is set to content-type, and the value of the content-type header field is set to text/html to correct errors as much as possible.
  • step S7 if the maximum value of the similarity is greater than a preset similarity threshold, then the incorrect header field name or incorrect header field value is replaced with the similarity
  • the largest header field name or header field value to obtain the adapted HTTP request header after step S7 includes:
  • the judgment of whether the header of the adapted HTTP request message is correct is realized. Although the aforementioned correction processing of the HTTP request header has been carried out, there is no guarantee that all incorrect HTTP request headers have been correctly corrected. If no error is reported during the process of identifying the HTTP request message with the adapted HTTP request message header, it is determined that the adapted HTTP request message header is correct.
  • the header field name and the header field value are obtained by parsing the HTTP request message header, and it is determined whether the header field name or the header field value is correct, and the calculation The similarity between the header field name or header field value in the preset replacement list and the incorrect header field name or incorrect header field value, and the incorrect header field name or incorrect The correct header field value is replaced with the header field name or header field value with the greatest similarity, thereby realizing the automatic correction of the incorrectly adapted request message header and reducing unnecessary network overhead.
  • an embodiment of the present application provides a device for adapting HTTP request headers, including:
  • the message receiving unit 10 is configured to receive HTTP request messages
  • the message header obtaining unit 20 is configured to parse the HTTP request message according to the preset format of the HTTP request message to obtain the HTTP request message header;
  • the header field name and header field value acquiring unit 30 is configured to parse the HTTP request header according to a preset HTTP request header format to obtain header field names and header field values;
  • the message header judgment unit 40 is configured to judge whether the header field name or the header field value is correct according to a preset request header inspection rule
  • the similarity calculation unit 50 is configured to use a preset similarity algorithm to calculate the header field name or the header field value in the preset replacement list if the header field name or header field value is incorrect. Stating the similarity of incorrect header field names or incorrect header field values, and obtaining the header field name or header field value with the largest similarity in the replacement list;
  • the similarity determination unit 60 is used to determine whether the maximum value of the similarity is greater than a preset similarity threshold
  • the replacement unit 70 is configured to replace the incorrect header field name or incorrect header field value with the highest similarity if the maximum value of the similarity is greater than the preset similarity threshold. Header field name or header field value to obtain the adapted HTTP request header.
  • the message header obtaining unit 20 includes:
  • the position determining subunit of the message header is configured to determine the position of the HTTP request message header according to the preset format of the HTTP request message;
  • the format judging subunit of the message header is used to determine whether the content in the position of the HTTP request message header conforms to the preset HTTP request message header format
  • the message header marking subunit is used to extract the content in the position of the HTTP request message header if it conforms to the preset HTTP request message header format, and record it as the HTTP request message header.
  • the header field name and header field value obtaining unit 30 includes:
  • the colon position determining subunit is used to determine the position of the first colon from the HTTP request message header
  • the header field name marking subunit is used to intercept the content before the first colon in the HTTP request message header and record it as the header field name;
  • the header field value marking subunit is used to intercept the content after the first colon in the HTTP request header and record it as the header field value.
  • the header field value includes a type part and a subtype part
  • the message header judging unit 40 includes:
  • a header field value parsing subunit for parsing the header field value to obtain a type part and a subtype part
  • a replacement list judging subunit configured to judge whether the header field name, the type part, or the subtype part exists in the preset replacement list
  • the correct determination subunit is used for determining that the header field name or the header field value is correct if the header field name, the type part, and the subtype part are all in the preset replacement list .
  • the similarity calculation unit 50 includes:
  • A is the incorrect header
  • B is the character frequency vector of the header field name or header field value in the preset replacement list
  • Ai and Bi are the vector A and B respectively
  • n is the value of the component vector with the largest number of component vectors in both vectors A and B, and the header field name or header field value with the greatest similarity in the replacement list is obtained.
  • the device includes:
  • a header field name setting unit configured to set the header field name to content-type if the maximum value in the similarity is not greater than a preset similarity threshold
  • the value setting unit of the header field is used to set the value of the content-type header field to text/html.
  • the device includes:
  • the identification command execution unit is used to execute the identification command of the HTTP request message with the adapted HTTP request header;
  • An error judgment unit for judging whether an error is reported in the identification process
  • the packet header correctness determining unit is configured to determine that the adapted HTTP request packet header is correct if no error is reported in the process of executing the identification command.
  • the HTTP request header adaptation device of the present application obtains header field names and header field values by parsing the HTTP request headers, determines whether the header field names or header field values are correct, and calculates The similarity between the header field name or header field value in the preset replacement list and the incorrect header field name or incorrect header field value, and the incorrect header field name or incorrect The correct header field value is replaced with the header field name or header field value with the greatest similarity, thereby realizing the automatic correction of the incorrectly adapted request message header and reducing unnecessary network overhead.
  • an embodiment of the present application also provides a computer device.
  • the computer device may be a server, and its internal structure may be as shown in the figure.
  • the computer equipment includes a processor, a memory, a network interface and a database connected by a system bus. Among them, the computer designed processor is used to provide calculation and control capabilities.
  • the memory of the computer device includes a non-volatile storage medium and an internal memory.
  • the non-volatile storage medium stores an operating system, a computer program, and a database.
  • the memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium.
  • the database of the computer equipment is used to store the data used in the adaptation method of the HTTP request message header.
  • the network interface of the computer device is used to communicate with an external terminal through a network connection.
  • the foregoing processor executes the foregoing HTTP request header adaptation method, wherein the steps included in the method respectively correspond to the steps of executing the HTTP request header adaptation method of the foregoing embodiment, and will not be repeated here.
  • the computer device of the present application obtains the header field name and header field value by analyzing the HTTP request message header, determines whether the header field name or header field value is correct, and calculates the value in the preset replacement list The similarity between the header field name or header field value and the incorrect header field name or incorrect header field value, replace the incorrect header field name or incorrect header field value It is the header field name or the header field value with the greatest similarity, thereby realizing the automatic correction of the incorrectly adapted request message header and reducing unnecessary network overhead.
  • An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored.
  • a computer program is executed by a processor, a method for adapting HTTP request headers is realized, wherein the steps included in the method are respectively executed
  • the steps of the method for adapting the HTTP request header of the foregoing embodiment correspond one-to-one, and will not be repeated here.
  • the computer-readable storage medium of the present application obtains the header field name and the header field value by parsing the HTTP request message header, determines whether the header field name or the header field value is correct, and calculates the preset replacement The similarity between the header field name or header field value in the list and the incorrect header field name or incorrect header field value, and the incorrect header field name or incorrect header The field value is replaced with the header field name or the header field value with the greatest similarity, thereby realizing the automatic correction of the incorrectly adapted request message header and reducing unnecessary network overhead.
  • Non-volatile memory may include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory.
  • Volatile memory may include random access memory (RAM) or external cache memory.
  • RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual-rate data rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous Link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

一种HTTP请求报文头的适配方法、装置、计算机设备和存储介质,包括:接收HTTP请求报文;解析HTTP请求报文,获得HTTP请求报文头;解析HTTP请求报文头,获得头部字段名及头部字段值;若头部字段名或者头部字段值不正确,计算预设的替换列表中的头部字段名或者头部字段值与不正确的头部字段名或者不正确的头部字段值的相似度;若相似度中的最大值大于预设的相似度阈值,则替换为所述相似度最大的头部字段名或者头部字段值,从而获得适配后的HTTP请求报文头。从而实现了自动纠正适配错误的请求报文头,减少不必要的网络开销。

Description

HTTP请求报文头的适配方法、装置和计算机设备
本申请要求于2019年1月31日提交中国专利局、申请号为201910101298.8,发明名称为“HTTP请求报文头的适配方法、装置和计算机设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及到计算机领域,特别是涉及到一种HTTP请求报文头的适配方法、装置、计算机设备和存储介质。
背景技术
报文是网络中交换与传输的数据单元,是各个系统、各个终端、服务器与终端之间交互的数据。报文包含了将要发送的完整的数据信息,至少包括了报文头与报文正文(即报文体)。其中请求报文即是向服务器发送请求的报文。服务器对于请求报文的识别是基于请求报文头。若请求报文头出现错误,例如字符错误、格式错误,会导致服务器不能识别请求报文,进而拒绝本次请求报文。其中,有些请求报文头的错误是可以进行纠正的,但是现有技术并没有纠正错误的请求报文头,从而减少不必要的报文发送次数的技术方案。
技术问题
本申请的主要目的为提供一种HTTP请求报文头的适配方法、装置、计算机设备和存储介质,旨在自动纠正适配错误的请求报文头,从而减少不必要网络开销。
技术解决方案
为了实现上述发明目的,本申请提出一种HTTP请求报文头的适配方法,包括以下步骤:
接收HTTP请求报文;
根据预设的HTTP请求报文的格式,解析所述HTTP请求报文,获得HTTP请求报文头;
根据预设的HTTP请求报文头的格式,解析所述HTTP请求报文头,获得头部字段名及头部字段值;
根据预设的请求报文头检验规则,判断所述头部字段名或者头部字段值是否正确;
若所述头部字段名或者头部字段值不正确,则采用预设的相似度算法计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值;
判断所述相似度中的最大值是否大于预设的相似度阈值;
若所述相似度中的最大值大于预设的相似度阈值,则将所述不正确的头部字段名或者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,从而获得适配后的HTTP请求报文头。
本申请提供一种HTTP请求报文头的适配装置,包括:
报文接收单元,用于接收HTTP请求报文;
报文头获取单元,用于根据预设的HTTP请求报文的格式,解析所述HTTP请求报文,获得HTTP请求报文头;
头部字段名及头部字段值获取单元,用于根据预设的HTTP请求报文头的格式,解析所述HTTP请求报文头,获得头部字段名及头部字段值;
报文头判断单元,用于根据预设的请求报文头检验规则,判断所述头部字段名或者头部字段值是否正确;
相似度计算单元,用于若所述头部字段名或者头部字段值不正确,则采用预设的相似度算法计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值;
相似度判断单元,用于判断所述相似度中的最大值是否大于预设的相似度阈值;
替换单元,用于若所述相似度中的最大值大于预设的相似度阈值,则将所述不正确的头部字段名或者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,从而获得适配后的HTTP请求报文头。
本申请提供一种计算机设备,包括存储器和处理器,所述存储器存储有计算机程序,所述处理器执行所述计算机程序时实现上述任一项所述方法的步骤。
本申请提供一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现上述任一项所述的方法的步骤。
有益效果
本申请的HTTP请求报文头的适配方法、装置、计算机设备和存储介质,通过解析所述HTTP请求报文头,获得头部字段名及头部字段值,判断所述头部字段名或者头部字段值是否正确,计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,将所述不正确的头部字段名或者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,从而实现了自动纠正适配错误的请求报文头,减少不必要网络开销。
附图说明
图1为本申请一实施例的HTTP请求报文头的适配方法的流程示意图;
图2为本申请一实施例的HTTP请求报文头的适配装置的结构示意框图;
图3为本申请一实施例的计算机设备的结构示意框图。
本申请目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。
本发明的最佳实施方式
为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。
参照图1,本申请实施例提供一种HTTP请求报文头的适配方法,包括以下步骤:
S1、接收HTTP请求报文;
S2、根据预设的HTTP请求报文的格式,解析所述HTTP请求报文,获得HTTP请求报文头;
S3、根据预设的HTTP请求报文头的格式,解析所述HTTP请求报文头,获得头部字段名及头部字段值;
S4、根据预设的请求报文头检验规则,判断所述头部字段名或者头部字段值是否正确;
S5、若所述头部字段名或者头部字段值不正确,则采用预设的相似度算法计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值;
S6、判断所述相似度中的最大值是否大于预设的相似度阈值;
S7、若所述相似度中的最大值大于预设的相似度阈值,则将所述不正确的头部字段名或者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,从而获得适配后的HTTP请求报文头。
如上述步骤S1所述,接收HTTP请求报文。报文是网络中交换与传输的数据单元,是各个系统、各个终端、服务器与终端之间交互的数据。报文包含了将要发送的完整的数据信息,至少包括了报文头与报文正文(即报文体)。其中请求报文是指发送请求的报文。
如上述步骤S2所述,根据预设的HTTP请求报文的格式,解析所述HTTP请求报文,获得HTTP请求报文头。一般,HTTP请求报文的格式为:请求行、请求头(HTTP请求报文头,也称HEADER)和请求体。预设的HTTP请求报文的格式即可设为请求行、请求头和请求体的格式,当然,也可设为其他任意的包括HTTP请求报文头的格式。其中,解析所述HTTP请求报文的过程包括:确定所述HTTP请求报文头的位置,从所述位置中提取出所述HTTP请求报文头。
如上述步骤S3所述,根据预设的HTTP请求报文头的格式,解析所述HTTP请求报文头,获得头部字段名及头部字段值。一般,HTTP请求报文头的格式为:头部字段名:头部字段值。预设的HTTP请求报文头的格式即设为头部字段名:头部字段值,当然,也可设为其他任意的包括头部字段名和与头部字段值的格式。具体的HTTP请求报文头的格式例如:Content-Type:[type]/[subtype];parameter。Content-type即为头部字段名,[type]/[subtype];parameter即为头部字段值。完整的HTTP请求报文头例如:Content-Type:application/json;charset=utf-8。parameter可以用来指定附加的信息,优选用于指定文 字编码方式的charset参数。据此,解析所述HTTP请求报文头,获得头部字段名及头部字段值。
如上述步骤S4所述,根据预设的请求报文头检验规则,判断所述头部字段名或者头部字段值是否正确。HTTP请求头若出现错误,则无法被识别,服务器无法接收该HTTP请求。其中,有些HTTP请求头的错误是可以判断出错误之处,并加以纠正的。因此,先根据预设的请求报文头检验规则,判断所述头部字段名或者头部字段值是否正确。若所述头部字段名或者头部字段值均正确,那么无需纠错,即可直接识别所述HTTP请求;若所述头部字段名或者头部字段值存在错误之处,那么可以对其进行纠正,再识别出纠正后的正确HTTP请求。其中,预设的请求报文头检验规则可以为任意检验请求报文头的方式,例如,先判断所述头部字段名是否存在于预设的正确头部字段名的表格中,若存在表明所述头部字段名无误,若不存在表明所述头部字段名有误;再判断所述头部字段值的名称与格式是否符合预设的名称与格式,若符合则判定无误,反之判定有误。
如上述步骤S5所述,若所述头部字段名或者头部字段值不正确,则采用预设的相似度算法计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值。若所述头部字段名或者头部字段值不正确,即HTTP请求无法被正确识别,因此需要先找出正确的头部字段名或者头部字段值。一般头部字段名及头部字段值不正确,仅是部分字符出错,例如,将Content-Type:application/json;charset=utf-8错误写成apolication/json;charset=utf-8等等。由于预设的替换列表中记载有例如application的正确头部字段名及头部字段值,因此计算HTTP请求头中的头部字段名及头部字段值与替换列表中的头部字段名及头部字段值的相似度,即可找出正确的头部字段名及头部字段值。其中,采用预设的相似度算法计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,可以采用任意相似度算法,例如重叠词算法等。
如上述步骤S6所述,判断所述相似度中的最大值是否大于预设的相似度阈值。若所述相似度中的最大值大于预设的相似度阈值,表明确在正确的头部字段名或者头部字段值,从而可以进行替换处理;反之,无法替换。
如上述步骤S7所述,若所述相似度中的最大值大于预设的相似度阈值,则将所述不正确的头部字段名或者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,从而获得适配后的HTTP请求报文头。若所述相似度大于预设的相似度阈值,表明预设的替换表中存在正确的头部字段名。据此,将所述不正确的头部字段名或者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,即可实现对错误的HTTP请求头的纠正,从而使HTTP请求得以被正确识别。其中替换所述不正确的头部字段值的方式包括:替换所述不正确的头部字段值中的不正确部分。即采用部分替换的方式替换不正确的头部字段值,这是因为头部字段值包括[type]/[subtype];parameter,其中,参数parameter 一般不会出错,因此只需将出错的[type]或者[subtype]进行替换即可。
在一个实施方式中,所述根据预设的HTTP请求报文的格式,解析所述HTTP请求报文,获得HTTP请求报文头的步骤S2,包括:
S201、根据预设的HTTP请求报文的格式,确定所述HTTP请求报文头的位置;
S202、判断所述HTTP请求报文头的位置中的内容是否与符合预设的HTTP请求报文头的格式;
S203、若符合预设的HTTP请求报文头的格式,则提取所述HTTP请求报文头的位置中的内容,并记为HTTP请求报文头。
如上所述,实现了根据预设的HTTP请求报文的格式,解析所述HTTP请求报文,获得HTTP请求报文头。以预设的HTTP请求报文的格式为请求行、请求头和请求体,其中请求行与请求头间存在第一个换行符,请求头与请求体之间存在一个空行,来举例。从所述HTTP请求报文中找到第一个换行符,再找到第一个空行,将所述第一个换行符与所述第一个空行之间的位置记为所述HTTP请求报文头的位置。再判断所述HTTP请求报文头的位置中的内容是否与符合预设的HTTP请求报文头的格式,例如判断是否具有Content-Type:[type]/[subtype];parameter的格式。若符合,则提取所述HTTP请求报文头的位置中的内容,并记为HTTP请求报文头。
在一个实施方式中,所述根据预设的HTTP请求报文头的格式,解析所述HTTP请求报文头,获得头部字段名及头部字段值的步骤S3,包括:
S301、从所述HTTP请求报文头中确定第一个冒号的位置;
S302、截取所述HTTP请求报文头中所述第一个冒号之前的内容,记为头部字段名;
S303、截取所述HTTP请求报文头中所述第一个冒号之后的内容,记为头部字段值。
如上所述,实现了根据预设的HTTP请求报文头的格式,解析所述HTTP请求报文头,获得头部字段名及头部字段值。本实施方式中,预设的HTTP请求报文头的格式为头部字段名:头部字段值,例如Content-Type:[type]/[subtype];parameter。即头部字段名与头部字段值通过冒号隔开,其中头部字段名里不存在冒号。因此截取所述HTTP请求报文头中所述第一个冒号之前的内容,记为头部字段名;截取所述HTTP请求报文头中所述第一个冒号之后的内容,记为头部字段值。其中,所述冒号的格式为任意格式的冒号,优选为英文格式的冒号。
在一个实施方式中,所述头部字段值包括类型部分和子类型部分,所述根据预设的请求报文头检验规则,判断所述头部字段名或者头部字段值是否正确的步骤S4,包括:
S401、解析所述头部字段值,获得类型部分和子类型部分;
S402、判断所述头部字段名、所述类型部分或者所述子类型部分是否存在所述预设的替换列表中;
S403、若所述头部字段名、所述类型部分和所述子类型部分均存在所述预设的替换列表中,则判定所述头部字段名或者头部字段值正确。
如上所述,实现了所述根据预设的请求报文头检验规则,判断所述头部字段名或者头部字段值是否正确。其中,所述头部字段值包括类型部分(例如type)和子类型部分(subtype)。而头部字段值中可能存在的参数(parameter)部分,一般不会出错,因此不做错误判断与替换的操作,以节省算力。再判断所述头部字段名、所述类型部分和所述子类型部分是否存在所述预设的替换列表中,即可判断所述头部字段名或者头部字段值是否正确。其中,所述替换列表中预存有正确的头部字段名、类型部分和子类型部分。
在一个实施方式中,所述若所述头部字段名或者头部字段值不正确,则采用预设的相似度算法计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值的步骤S5,包括:
S501、若所述头部字段名或者头部字段值不正确,则采用公式:
Figure PCTCN2019089053-appb-000001
计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度。其中,A为所述不正确的头部字段名或者不正确的头部字段值的字符频率向量,B为预设的替换列表中的头部字段名或者头部字段值的字符频率向量,Ai、Bi分别为所述向量A和B的第i个分向量,n为向量A和B二者中分向量数量最多的分向量数量值,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值。
如上所述,实现了若所述头部字段名或者头部字段值不正确,则采用预设的相似度算法计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值。其中,采用余弦相似度的计算方法来采用预设的相似度算法计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度。其中,头部字段名或者头部字段值的字符频率向量指头部字段名或者头部字段值中的字符出现的次数。例如start的字符频率向量为(1,2,1,1),即除t出现2次外,其他字符均只出现1次,其中(1,2,1,1)中的2即为字符t的分向量。从而,利用余弦相似度公式 计算出预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度。
在一个实施方式中,所述判断所述相似度中的最大值是否大于预设的相似度阈值的步骤S6之后,包括:
S61、若所述相似度中的最大值不大于预设的相似度阈值,则将所述头部字段名设置为content-type;
S62、将所述content-type头部字段的值设置为text/html。
如上所述,实现了将所述content-type头部字段的值设置为text/html。若所述相似度中的最大值不大于预设的相似度阈值,表明不能找到正确的所述头部字段名或者头部字段值。而一般情况下,头部字段名为content-type、头部字段值为text/html是较常见的情况,有可能纠正HTTP请求头的错误。因此将所述头部字段名设置为content-type,将所述content-type头部字段的值设置为text/html,以尽可能地纠正错误。
在一个实施方式中,所述若所述相似度中的最大值大于预设的相似度阈值,则将所述不正确的头部字段名或者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,从而获得适配后的HTTP请求报文头的步骤S7之后,包括:
S71、执行对具有适配后的HTTP请求报文头的HTTP请求报文的识别命令;
S72、判断所述识别过程是否报错;
S73、若执行所述识别命令的过程未报错,则判定所述适配的HTTP请求报文头正确。
如上所述,实现了对所述适配的HTTP请求报文头是否正确的判断。虽然前述已经经过了对HTTP请求报文头的纠正处理,但是不能保证所有的错误HTTP请求报文头都得到了正确的纠正。若在执行对具有适配后的HTTP请求报文头的HTTP请求报文的识别过程,并未报错,则判定所述适配的HTTP请求报文头正确。
本申请的HTTP请求报文头的适配方法,通过解析所述HTTP请求报文头,获得头部字段名及头部字段值,判断所述头部字段名或者头部字段值是否正确,计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,将所述不正确的头部字段名或者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,从而实现了自动纠正适配错误的请求报文头,减少不必要网络开销。
参照图2,本申请实施例提供一种HTTP请求报文头的适配装置,包括:
报文接收单元10,用于接收HTTP请求报文;
报文头获取单元20,用于根据预设的HTTP请求报文的格式,解析所述HTTP请求报文,获得HTTP请求报文头;
头部字段名及头部字段值获取单元30,用于根据预设的HTTP请求报文头的格式,解析所述HTTP请求报文头,获得头部字段名及头部字段值;
报文头判断单元40,用于根据预设的请求报文头检验规则,判断所述头部字段名或者头部字段值是否正确;
相似度计算单元50,用于若所述头部字段名或者头部字段值不正确,则采用预设的相似度算法计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值;
相似度判断单元60,用于判断所述相似度中的最大值是否大于预设的相似度阈值;
替换单元70,用于若所述相似度中的最大值大于预设的相似度阈值,则将所述不正确的头部字段名或者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,从而获得适配后的HTTP请求报文头。
其中上述单元分别用于执行的操作与前述实施方式的HTTP请求报文头的适配方法的步骤一一对应,在此不再赘述。
在一个实施方式中,所述报文头获取单元20,包括:
报文头的位置确定子单元,用于根据预设的HTTP请求报文的格式,确定所述HTTP请求报文头的位置;
报文头的格式判断子单元,用于判断所述HTTP请求报文头的位置中的内容是否与符合预设的HTTP请求报文头的格式;
报文头标记子单元,用于若符合预设的HTTP请求报文头的格式,则提取所述HTTP请求报文头的位置中的内容,并记为HTTP请求报文头。
其中上述子单元分别用于执行的操作与前述实施方式的HTTP请求报文头的适配方法的步骤一一对应,在此不再赘述。
在一个实施方式中,所述头部字段名及头部字段值获取单元30,包括:
冒号位置确定子单元,用于从所述HTTP请求报文头中确定第一个冒号的位置;
头部字段名标记子单元,用于截取所述HTTP请求报文头中所述第一个冒号之前的内容,记为头部字段名;
头部字段值标记子单元,用于截取所述HTTP请求报文头中所述第一个冒号之后的内容,记为头部字段值。
其中上述子单元分别用于执行的操作与前述实施方式的HTTP请求报文头的适配方法的步骤一一对应,在此不再赘述。
在一个实施方式中,所述头部字段值包括类型部分和子类型部分,所述报文头判断单元40,包括:
头部字段值解析子单元,用于解析所述头部字段值,获得类型部分和子类型部分;
替换列表判断子单元,用于判断所述头部字段名、所述类型部分或者所述子类型部分是否存在所述预设的替换列表中;
正确判定子单元,用于若所述头部字段名、所述类型部分和所述子类型部分均存在所述预设的替换列表中,则判定所述头部字段名或者头部字段值正确。
其中上述子单元分别用于执行的操作与前述实施方式的HTTP请求报文头的适配方法的步骤一一对应,在此不再赘述。
在一个实施方式中,所述相似度计算单元50,包括:
相似度计算子单元,用于若所述头部字段名或者头部字段值不正确,则采用公式:
Figure PCTCN2019089053-appb-000002
计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,其中,A为所述不正确的头部字段名或者不正确的头部字段值的字符频率向量,B为预设的替换列表中的头部字段名或者头部字段值的字符频率向量,Ai、Bi分别为所述向量A和B的第i个分向量,n为向量A和B二者中分向量数量最多的分向量数量值,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值。
其中上述子单元分别用于执行的操作与前述实施方式的HTTP请求报文头的适配方法的步骤一一对应,在此不再赘述。
在一个实施方式中,所述装置,包括:
头部字段名设置单元,用于若所述相似度中的最大值不大于预设的相似度阈值,则将所述头部字段名设置为content-type;
头部字段的值设置单元,用于将所述content-type头部字段的值设置为text/html。
其中上述单元分别用于执行的操作与前述实施方式的HTTP请求报文头的适配方法的步骤一一对应,在此不再赘述。
在一个实施方式中,所述装置,包括:
识别命令执行单元,用于执行对具有适配后的HTTP请求报文头的HTTP请求报文的识别命令;
报错判断单元,用于判断所述识别过程是否报错;
报文头正确判定单元,用于若执行所述识别命令的过程未报错,则判定所述适配的HTTP请求报文头正确。
其中上述单元分别用于执行的操作与前述实施方式的HTTP请求报文头的适配方法的步骤一一对应,在此不再赘述。
本申请的HTTP请求报文头的适配装置,通过解析所述HTTP请求报文头,获得头部字段名及头部字段值,判断所述头部字段名或者头部字段值是否正确,计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,将所述不正确的头部字段名或者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,从而实现了自动纠正适配错误的请求报文头,减少不必要网络开销。
参照图3,本申请实施例中还提供一种计算机设备,该计算机设备可以是服务器,其内部结构可以如图所示。该计算机设备包括通过系统总线连接的处理器、存储器、网络接口和数据库。其中,该计算机设计的处理器用于提供计算和控制能力。该计算机设备的存储器包括非易失性存储介质、内存储器。该非易失性存储介质存储有操作系统、计算机程序和数据库。该内存器为非易失性存储介质中的操作系统和计算机程序的运行提供环境。该计算机设备的数据库用于存储HTTP请求报文头的适配方法所用数据。该计算机设备的网络接口用于与外部的终端通过网络连接通信。该计算机程序被处理器执行时以实现一种HTTP请求报文头的适配方法。
上述处理器执行上述HTTP请求报文头的适配方法,其中所述方法包括的步骤分别与执行前述实施方式的HTTP请求报文头的适配方法的步骤一一对应,在此不再赘述。
本领域技术人员可以理解,图中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备的限定。
本申请的计算机设备,通过解析所述HTTP请求报文头,获得头部字段名及头部字段值,判断所述头部字段名或者头部字段值是否正确,计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,将所述不正确的头部字段名或者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,从而实现了自动纠正适配错误的请求报文头,减少不必要网络开销。
本申请一实施例还提供一种计算机可读存储介质,其上存储有计算机程序,计算机程序被处理器执行时实现HTTP请求报文头的适配方法,其中所述方法包括的步骤分别与执行前述实施方式的HTTP请求报文头的适配方法的步骤一一对应,在此不再赘述。
本申请的计算机可读存储介质,通过解析所述HTTP请求报文头,获得头部字段名及头部字段值,判断所述头部字段名或者头部字段值是否正确,计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,将所述不正确的头部字段名或者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,从而实现了自动纠正适配错误的请求报文头,减少不必要网络开销。
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一非易失性计算机可读取存储介质中,该计算机程序在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的和实施例中所使用的对存储器、存储、数据库或其它介质的任何引用,均可包括非易失性和/或易失性存储器。非易失性存储器可以包括只读存储器(ROM)、可编程ROM(PROM)、电可编程ROM(EPROM)、电可擦除可编程ROM(EEPROM)或闪存。易失性存储器可包括随机存取存储器(RAM)或者外部高速缓冲存储器。作为说明而非局限,RAM以多种形式可得,诸如静态RAM(SRAM)、动态RAM(DRAM)、同步DRAM(SDRAM)、双速据率SDRAM(SSRSDRAM)、增强型SDRAM(ESDRAM)、同步链路(Synchlink)DRAM(SLDRAM)、存储器总线(Rambus)直接RAM(RDRAM)、直接存储器总线动态RAM(DRDRAM)、以及存储器总线动态RAM(RDRAM)等。
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、装置、物品或者方法不仅包括那些要素,而且还包括没有明确列出的其 他要素,或者是还包括为这种过程、装置、物品或者方法所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、装置、物品或者方法中还存在另外的相同要素。
以上所述仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本申请的专利保护范围内。

Claims (20)

  1. 一种HTTP请求报文头的适配方法,其特征在于,包括:
    接收HTTP请求报文;
    根据预设的HTTP请求报文的格式,解析所述HTTP请求报文,获得HTTP请求报文头;
    根据预设的HTTP请求报文头的格式,解析所述HTTP请求报文头,获得头部字段名及头部字段值;
    根据预设的请求报文头检验规则,判断所述头部字段名或者头部字段值是否正确;
    若所述头部字段名或者头部字段值不正确,则采用预设的相似度算法计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值;
    判断所述相似度中的最大值是否大于预设的相似度阈值;
    若所述相似度中的最大值大于预设的相似度阈值,则将所述不正确的头部字段名或者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,从而获得适配后的HTTP请求报文头。
  2. 根据权利要求1所述的HTTP请求报文头的适配方法,其特征在于,所述根据预设的HTTP请求报文的格式,解析所述HTTP请求报文,获得HTTP请求报文头的步骤,包括:
    根据预设的HTTP请求报文的格式,确定所述HTTP请求报文头的位置;
    判断所述HTTP请求报文头的位置中的内容是否与符合预设的HTTP请求报文头的格式;
    若符合预设的HTTP请求报文头的格式,则提取所述HTTP请求报文头的位置中的内容,并记为HTTP请求报文头。
  3. 根据权利要求1所述的HTTP请求报文头的适配方法,其特征在于,所述根据预设的HTTP请求报文头的格式,解析所述HTTP请求报文头,获得头部字段名及头部字段值的步骤,包括:
    从所述HTTP请求报文头中确定第一个冒号的位置;
    截取所述HTTP请求报文头中所述第一个冒号之前的内容,记为头部字段名;
    截取所述HTTP请求报文头中所述第一个冒号之后的内容,记为头部字段值。
  4. 根据权利要求1所述的HTTP请求报文头的适配方法,其特征在于,所述头部字段值包括类型部分和子类型部分,所述根据预设的请求报文头检验规则,判断所述头部字段名或者头部字段值是否正确的步骤,包括:
    解析所述头部字段值,获得类型部分和子类型部分;
    判断所述头部字段名、所述类型部分或者所述子类型部分是否存在所述预设的替换列表中;
    若所述头部字段名、所述类型部分和所述子类型部分均存在所述预设的替换列表中,则判定所述头部字段名或者头部字段值正确。
  5. 根据权利要求1所述的HTTP请求报文头的适配方法,其特征在于,所述若所述头部字段名或者头部字段值不正确,则采用预设的相似度算法计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值的步骤,包括:
    若所述头部字段名或者头部字段值不正确,则采用公式:
    Figure PCTCN2019089053-appb-100001
    计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度similarity,其中,A为所述不正确的头部字段名或者不正确的头部字段值的字符频率向量,B为预设的替换列表中的头部字段名或者头部字段值的字符频率向量,Ai、Bi分别为所述向量A和B的第i个分向量,n为向量A和B二者中分向量数量最多的分向量数量值,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值。
  6. 根据权利要求1所述的HTTP请求报文头的适配方法,其特征在于,所述判断所述相似度中的最大值是否大于预设的相似度阈值的步骤之后,包括:
    若所述相似度中的最大值不大于预设的相似度阈值,则将所述头部字段名设置为content-type;
    将所述content-type头部字段的值设置为text/html。
  7. 一种HTTP请求报文头的适配装置,其特征在于,包括:
    报文接收单元,用于接收HTTP请求报文;
    报文头获取单元,用于根据预设的HTTP请求报文的格式,解析所述HTTP请求报文,获得HTTP请求报文头;
    头部字段名及头部字段值获取单元,用于根据预设的HTTP请求报文头的格式,解析所述HTTP请求报文头,获得头部字段名及头部字段值;
    报文头判断单元,用于根据预设的请求报文头检验规则,判断所述头部字段名或者头部字段值是否正确;
    相似度计算单元,用于若所述头部字段名或者头部字段值不正确,则采用预设的相似度算法计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值;
    相似度判断单元,用于判断所述相似度中的最大值是否大于预设的相似度阈值;
    替换单元,用于若所述相似度中的最大值大于预设的相似度阈值,则将所述不正确的头部字段名或 者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,从而获得适配后的HTTP请求报文头。
  8. 根据权利要求7所述的HTTP请求报文头的适配方法,其特征在于,所述报文头获取单元,包括:
    报文头的位置确定子单元,用于根据预设的HTTP请求报文的格式,确定所述HTTP请求报文头的位置;
    报文头的格式判断子单元,用于判断所述HTTP请求报文头的位置中的内容是否与符合预设的HTTP请求报文头的格式;
    报文头标记子单元,用于若符合预设的HTTP请求报文头的格式,则提取所述HTTP请求报文头的位置中的内容,并记为HTTP请求报文头。
  9. 根据权利要求7所述的HTTP请求报文头的适配方法,其特征在于,所述头部字段名及头部字段值获取单元,包括:
    冒号位置确定子单元,用于从所述HTTP请求报文头中确定第一个冒号的位置;
    头部字段名标记子单元,用于截取所述HTTP请求报文头中所述第一个冒号之前的内容,记为头部字段名;
    头部字段值标记子单元,用于截取所述HTTP请求报文头中所述第一个冒号之后的内容,记为头部字段值。
  10. 根据权利要求7所述的HTTP请求报文头的适配方法,其特征在于,所述头部字段值包括类型部分和子类型部分,所述报文头判断单元,包括:
    头部字段值解析子单元,用于解析所述头部字段值,获得类型部分和子类型部分;
    替换列表判断子单元,用于判断所述头部字段名、所述类型部分或者所述子类型部分是否存在所述预设的替换列表中;
    正确判定子单元,用于若所述头部字段名、所述类型部分和所述子类型部分均存在所述预设的替换列表中,则判定所述头部字段名或者头部字段值正确。
  11. 根据权利要求7所述的HTTP请求报文头的适配方法,其特征在于,所述相似度计算单元50,包括:
    相似度计算子单元,用于若所述头部字段名或者头部字段值不正确,则采用公式:
    Figure PCTCN2019089053-appb-100002
    计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,其中,A为所述不正确的头部字段名或者不正确的头部字段值的字符频率向量,B为预设的替换列表中的头部字段名或者头部字段值的字符频率向量,Ai、Bi分别为所述向量A和B的第i个分向量,n为向量A和B二者中分向量数量最多的分向量数量值,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值。
  12. 根据权利要求7所述的HTTP请求报文头的适配方法,其特征在于,所述所述装置,包括:
    头部字段名设置单元,用于若所述相似度中的最大值不大于预设的相似度阈值,则将所述头部字段名设置为content-type;
    头部字段的值设置单元,用于将所述content-type头部字段的值设置为text/html。
  13. 一种计算机设备,包括存储器和处理器,所述存储器存储有计算机可读指令,其特征在于,所述处理器执行所述计算机可读指令时实现HTTP请求报文头的适配方法,该HTTP请求报文头的适配方法,包括:
    接收HTTP请求报文;
    根据预设的HTTP请求报文的格式,解析所述HTTP请求报文,获得HTTP请求报文头;
    根据预设的HTTP请求报文头的格式,解析所述HTTP请求报文头,获得头部字段名及头部字段值;
    根据预设的请求报文头检验规则,判断所述头部字段名或者头部字段值是否正确;
    若所述头部字段名或者头部字段值不正确,则采用预设的相似度算法计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值;
    判断所述相似度中的最大值是否大于预设的相似度阈值;
    若所述相似度中的最大值大于预设的相似度阈值,则将所述不正确的头部字段名或者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,从而获得适配后的HTTP请求报文头。
  14. 根据权利要求13所述的计算机设备,其特征在于,所述根据预设的HTTP请求报文的格式,解析所述HTTP请求报文,获得HTTP请求报文头的步骤,包括:
    根据预设的HTTP请求报文的格式,确定所述HTTP请求报文头的位置;
    判断所述HTTP请求报文头的位置中的内容是否与符合预设的HTTP请求报文头的格式;
    若符合预设的HTTP请求报文头的格式,则提取所述HTTP请求报文头的位置中的内容,并记为HTTP请求报文头。
  15. 根据权利要求13所述的计算机设备,其特征在于,所述根据预设的HTTP请求报文头的格式,解析所述HTTP请求报文头,获得头部字段名及头部字段值的步骤,包括:
    从所述HTTP请求报文头中确定第一个冒号的位置;
    截取所述HTTP请求报文头中所述第一个冒号之前的内容,记为头部字段名;
    截取所述HTTP请求报文头中所述第一个冒号之后的内容,记为头部字段值。
  16. 根据权利要求13所述的计算机设备,其特征在于,所述头部字段值包括类型部分和子类型部分,所述根据预设的请求报文头检验规则,判断所述头部字段名或者头部字段值是否正确的步骤,包括:
    解析所述头部字段值,获得类型部分和子类型部分;
    判断所述头部字段名、所述类型部分或者所述子类型部分是否存在所述预设的替换列表中;
    若所述头部字段名、所述类型部分和所述子类型部分均存在所述预设的替换列表中,则判定所述头部字段名或者头部字段值正确。
  17. 一种计算机非易失性可读存储介质,其上存储有计算机可读指令,其特征在于,所述计算机可读指令被处理器执行时实现HTTP请求报文头的适配方法,该HTTP请求报文头的适配方法,包括:
    接收HTTP请求报文;
    根据预设的HTTP请求报文的格式,解析所述HTTP请求报文,获得HTTP请求报文头;
    根据预设的HTTP请求报文头的格式,解析所述HTTP请求报文头,获得头部字段名及头部字段值;
    根据预设的请求报文头检验规则,判断所述头部字段名或者头部字段值是否正确;
    若所述头部字段名或者头部字段值不正确,则采用预设的相似度算法计算预设的替换列表中的头部字段名或者头部字段值与所述不正确的头部字段名或者不正确的头部字段值的相似度,并获得所述替换列表中的所述相似度最大的头部字段名或者头部字段值;
    判断所述相似度中的最大值是否大于预设的相似度阈值;
    若所述相似度中的最大值大于预设的相似度阈值,则将所述不正确的头部字段名或者不正确的头部字段值替换为所述相似度最大的头部字段名或者头部字段值,从而获得适配后的HTTP请求报文头。
  18. 根据权利要求17所述的计算机非易失性可读存储介质,其特征在于,所述根据预设的HTTP请求报文的格式,解析所述HTTP请求报文,获得HTTP请求报文头的步骤,包括:
    根据预设的HTTP请求报文的格式,确定所述HTTP请求报文头的位置;
    判断所述HTTP请求报文头的位置中的内容是否与符合预设的HTTP请求报文头的格式;
    若符合预设的HTTP请求报文头的格式,则提取所述HTTP请求报文头的位置中的内容,并记为HTTP请求报文头。
  19. 根据权利要求17所述的计算机非易失性可读存储介质,其特征在于,所述根据预设的HTTP请求报文头的格式,解析所述HTTP请求报文头,获得头部字段名及头部字段值的步骤,包括:
    从所述HTTP请求报文头中确定第一个冒号的位置;
    截取所述HTTP请求报文头中所述第一个冒号之前的内容,记为头部字段名;
    截取所述HTTP请求报文头中所述第一个冒号之后的内容,记为头部字段值。
  20. 根据权利要求17所述的计算机非易失性可读存储介质,其特征在于,所述头部字段值包括类型部分和子类型部分,所述根据预设的请求报文头检验规则,判断所述头部字段名或者头部字段值是否正确的步骤,包括:
    解析所述头部字段值,获得类型部分和子类型部分;
    判断所述头部字段名、所述类型部分或者所述子类型部分是否存在所述预设的替换列表中;
    若所述头部字段名、所述类型部分和所述子类型部分均存在所述预设的替换列表中,则判定所述头部字段名或者头部字段值正确。
PCT/CN2019/089053 2019-01-31 2019-05-29 Http请求报文头的适配方法、装置和计算机设备 WO2020155483A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910101298.8 2019-01-31
CN201910101298.8A CN109936624B (zh) 2019-01-31 2019-01-31 Http请求报文头的适配方法、装置和计算机设备

Publications (1)

Publication Number Publication Date
WO2020155483A1 true WO2020155483A1 (zh) 2020-08-06

Family

ID=66985475

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/089053 WO2020155483A1 (zh) 2019-01-31 2019-05-29 Http请求报文头的适配方法、装置和计算机设备

Country Status (2)

Country Link
CN (1) CN109936624B (zh)
WO (1) WO2020155483A1 (zh)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112528307A (zh) * 2020-12-18 2021-03-19 平安银行股份有限公司 服务请求校验方法、装置、电子设备及存储介质
CN114553676A (zh) * 2022-02-25 2022-05-27 湖南快乐阳光互动娱乐传媒有限公司 一种报文处理方法、平台、电子设备及存储介质
CN115314554A (zh) * 2022-09-26 2022-11-08 北京城建设计发展集团股份有限公司 一种轨道交通异构系统的数据接入方法、装置及系统

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110445636B (zh) * 2019-07-03 2022-03-18 平安科技(深圳)有限公司 基于管理平台的微服务预警方法、装置和计算机设备
CN112822237B (zh) * 2020-12-28 2022-07-15 北京奇艺世纪科技有限公司 网络请求传输方法及装置
CN113034151A (zh) * 2021-03-17 2021-06-25 中国工商银行股份有限公司 户名校验方法及装置、电子设备和计算机可读存储介质
CN115379026B (zh) * 2022-04-19 2024-01-19 国家计算机网络与信息安全管理中心 一种报文头域的识别方法、装置、设备及存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1450767A (zh) * 2002-04-10 2003-10-22 深圳市中兴通讯股份有限公司 一种数据包转发控制装置和方法
WO2009051898A1 (en) * 2007-10-19 2009-04-23 Citrix Systems, Inc. Systems and methods for managing cookies via http content layer
CN103220371A (zh) * 2012-01-18 2013-07-24 中国移动通信集团公司 内容适配方法及系统
CN103944817A (zh) * 2013-01-23 2014-07-23 中国银联股份有限公司 一种联机系统中的报文转接方法、转接设备以及终端设备

Family Cites Families (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
BRPI0212000B1 (pt) * 2001-08-23 2017-12-12 Polycom, Inc. "system and method for processing video data"
EP2129028B1 (en) * 2008-05-06 2012-10-17 Alcatel Lucent Recovery of transmission errorrs
CN102833327B (zh) * 2012-08-16 2016-03-02 瑞斯康达科技发展股份有限公司 基于http的客户端类型的识别方法和装置
CN103929447B (zh) * 2013-01-11 2017-07-07 中国科学院声学研究所 一种基于PEEK操作的解析HTTP chunked编码数据的方法
CN105959344B (zh) * 2016-04-15 2019-12-06 杭州迪普科技股份有限公司 一种Web推送方法及装置
CN106452954B (zh) * 2016-09-30 2019-08-27 苏州迈科网络安全技术股份有限公司 Http数据特征分析方法及系统
CN106878311B (zh) * 2017-02-22 2019-12-06 杭州迪普科技股份有限公司 Http报文的重写方法及装置
CN108681534A (zh) * 2018-04-11 2018-10-19 广州视源电子科技股份有限公司 候选词评估方法、装置、计算机设备和存储介质
CN108629046B (zh) * 2018-05-14 2023-08-18 平安科技(深圳)有限公司 一种字段匹配方法及终端设备
CN109150962B (zh) * 2018-07-03 2021-03-02 北京东方网信科技股份有限公司 一种通过关键字快速识别http请求头的方法
CN110377633A (zh) * 2019-06-21 2019-10-25 深圳壹账通智能科技有限公司 报表数据处理方法、装置、计算机设备和存储介质

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1450767A (zh) * 2002-04-10 2003-10-22 深圳市中兴通讯股份有限公司 一种数据包转发控制装置和方法
WO2009051898A1 (en) * 2007-10-19 2009-04-23 Citrix Systems, Inc. Systems and methods for managing cookies via http content layer
CN103220371A (zh) * 2012-01-18 2013-07-24 中国移动通信集团公司 内容适配方法及系统
CN103944817A (zh) * 2013-01-23 2014-07-23 中国银联股份有限公司 一种联机系统中的报文转接方法、转接设备以及终端设备

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112528307A (zh) * 2020-12-18 2021-03-19 平安银行股份有限公司 服务请求校验方法、装置、电子设备及存储介质
CN114553676A (zh) * 2022-02-25 2022-05-27 湖南快乐阳光互动娱乐传媒有限公司 一种报文处理方法、平台、电子设备及存储介质
CN115314554A (zh) * 2022-09-26 2022-11-08 北京城建设计发展集团股份有限公司 一种轨道交通异构系统的数据接入方法、装置及系统
CN115314554B (zh) * 2022-09-26 2024-01-26 北京城建设计发展集团股份有限公司 一种轨道交通异构系统的数据接入方法、装置及系统

Also Published As

Publication number Publication date
CN109936624A (zh) 2019-06-25
CN109936624B (zh) 2022-03-18

Similar Documents

Publication Publication Date Title
WO2020155483A1 (zh) Http请求报文头的适配方法、装置和计算机设备
CN110445636B (zh) 基于管理平台的微服务预警方法、装置和计算机设备
US10446146B2 (en) Learning apparatus and method
WO2019136990A1 (zh) 网络数据检测方法、装置、计算机设备和存储介质
CN111191281A (zh) 数据脱敏处理方法、装置、计算机设备及存储介质
WO2019223437A1 (zh) 一种语音翻译方法及装置
CN112613993B (zh) 交易数据处理方法、装置、计算机设备和存储介质
CN115048925B (zh) 一种确定异常文本的数据处理系统
WO2022134828A1 (zh) 基于图片识别的智能仓储方法、系统、设备及存储介质
CN112162924A (zh) 接口自动化测试方法、装置、计算机设备及存储介质
WO2019057023A1 (zh) 数据恢复方法、发送/接收装置和计算机可读存储介质
CN112751833A (zh) Rtp报文识别方法、装置、电子设备及可读存储介质
US11316930B2 (en) Connection control method and device
CN112612491A (zh) 配置热刷新方法、装置、计算机设备及存储介质
WO2020211233A1 (zh) 批量数据编辑方法、装置、计算机设备及存储介质
CN111835710B (zh) 校验请求体的方法、装置、计算机设备和存储介质
CN111176882A (zh) 特定数据处理方法、装置、计算机设备及存储介质
CN109446052B (zh) 一种应用程序的校验方法及设备
CN112528334B (zh) 基于区块链网络的数据获取方法、装置以及计算机设备
US20230368550A1 (en) Text extraction using optical character recognition
CN109918433B (zh) 基于通用数据接口的报文保存方法、装置和计算机设备
CN110110123B (zh) 检测模型的训练集更新方法和装置
EP3174246B1 (en) Method and device for sending bulk data acquisition request
CN111147473A (zh) 网络报文的转发方法、装置及系统
CN112101849B (zh) 核电站数据自动校验方法、装置、设备及介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19912825

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19912825

Country of ref document: EP

Kind code of ref document: A1