简体   繁体   English

强制没有内容类型的HTTP响应?

[英]Force HTTP response with no Content-type?

Is there some way to deliberately force a Perl CGI script to return an HTTP response with no Content-type header? 有什么方法可以故意强迫Perl CGI脚本返回没有Content-type标头的HTTP响应吗? This is for testing a diagnostic crawler that looks for various malformed headers. 这是用于测试诊断搜寻器,以查找各种格式错误的标头。

The closest I have gotten is this: 我得到的最接近的是:

#!/usr/bin/perl
print "Status: 200 OK\r\n";
print "Content-type:\r\n";
print "\r\n";
print "Message body goes here.\r\n";

This generates the following response: 这将产生以下响应:

HTTP/1.1 200 OK
Date: Mon, 13 Jan 2014 23:17:23 GMT
Server: Apache/2.2.14 (Ubuntu)
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: 
Content-Length: 25

Message body goes here.

But the content-type is still defined, it just has a value of "". 但是content-type仍然是定义的,它的值只有“”。 I really need to generate a response that has no content-type at all. 我真的需要生成一个根本没有内容类型的响应。

When I remove the line that prints the content-type: 当我删除打印内容类型的行时:

#!/usr/bin/perl
print "Status: 200 OK\r\n";
print "\r\n";
print "Message body goes here.\r\n";

Then the header gets added automatically: 然后标题将自动添加:

HTTP/1.1 200 OK
Date: Mon, 13 Jan 2014 23:19:00 GMT
Server: Apache/2.2.14 (Ubuntu)
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/plain
Content-Length: 25

Message body goes here.

Is there some way to bypass this behavior? 有什么办法可以绕过这种行为? Ideally I would like to do this as a Perl script running on a normally-configured Apache server. 理想情况下,我想作为在通常配置的Apache服务器上运行的Perl脚本来执行此操作。 If that isn't possible, is there some other way, maybe using a different language/server/configuration? 如果不可能,是否还有其他方法,也许使用其他语言/服务器/配置?

No, the CGI interface requires that the Content-type header is set, so any web server software that implements CGI correctly will give a 500 - Internal Server Error . 否,CGI界面要求设置Content-type标头,因此任何正确实现CGI的Web服务器软件都将给出500 - Internal Server Error

You'll actually have to implement your own HTTP server (or modify one) to get what you want. 实际上,您必须实现自己的HTTP服务器(或修改一个HTTP服务器)才能获得所需的内容。

That might be possible within Apache by implementing some mod_perl handler that runs after the Apache Response Handler (not sure one exists, or possibly by stacking handlers). 在Apache中,可以通过实现一些在Apache Response Handler之后运行的mod_perl处理程序 (不确定存在该方法,或者通过堆栈处理程序)来实现。 . edit: It appears you should implement a Response Filter. 编辑:看来您应该实现一个响应过滤器。 Apache2::Filter::HTTPHeadersFixup is one that does exactly what you asked for. Apache2 :: Filter :: HTTPHeadersFixup可以完全满足您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM