What is the “raw HTTP header”? What is the difference between “HTTP header” and “raw HTTP header”?

心已入冬 提交于 2019-12-06 01:38:54

问题


In Zend Framework in Response Class there are two different arrays for storing headers: _headers[] and _headersRaw[]. And there are appropriate methods for setting each one:

setHeader(), getHeaders(), clearHeader() and

setRawHeader(), getRawHeaders(), clearRawHeaders().

What is the reason to have "header" and "raw header"? Is there some special kind of usage in practice for each of these headers?


回答1:


using setHeader you set key vale pair without worrying about there formatting e.g

$this->getResponse()->setHeader('Content-type','json');

while in case of setRawHeader() you put the whole/full header as it is with proper formating




回答2:


I'm a bit late here...

Raw means that the header is not URL-encoded, whereas if the word "raw" is omitted, the header is encoded. For example:

$header = 'http://www.mywebsite.com?q=string'; // this is raw, no encoding

echo $header; // no encoding so output is -> http://www.mywebsite.com?q=mystring

echo rawurlencode($header); // URL-encoded so output is -> http%3A%2F%2Fwww.mywebsite.com%3Fq%3Dstring

The special characters : / ? = have been URL-encoded as

%3A %2F %3F %3D

respectively.



来源:https://stackoverflow.com/questions/11207070/what-is-the-raw-http-header-what-is-the-difference-between-http-header-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!