当前位置: 动力学知识库 > 问答 > 编程问答 >

Is it necessary to check both '\r\n\r\n' and '\n\n' as HTTP Header/Content separator?

问题描述:

The accepted answer on this page says we should check HTTP server responses for both \r\n\r\n and \n\n as the sequence that separates the headers from the content.

Like:

HTTP/1.1 200 Ok\r\n

Server: AAA\r\n

Cache-Control: no-cache\r\n

Date: Fri, 07 Nov 2014 23:20:27 GMT\r\n

Content-Type: text/html\r\n

Connection: close\r\n\r\n <--------------

or:

HTTP/1.1 200 Ok\r\n

Server: AAA\r\n

Cache-Control: no-cache\r\n

Date: Fri, 07 Nov 2014 23:20:27 GMT\r\n

Content-Type: text/html\r\n

Connection: close\n\n <--------------

In all the responses I've seen in Wireshark, servers use \r\n\r\n.

Is it really necessary to check for both? Which servers/protocol versions would use \n\n?

网友答案:

HTTP spec says:

The line terminator for message-header fields is the sequence CRLF. However, we recommend that applications, when parsing such headers, recognize a single LF as a line terminator and ignore the leading CR.

In practice I've never seen web server with CR line separator.

分享给朋友:
您可能感兴趣的文章:
随机阅读: