thttpd HTTP 支持级别

thttpd HTTP 支持级别

thttpd 是否只支持静态页面的 HTTP 1.1?CGI 生成的页面的 HTTP 请求似乎仅响应 HTTP 1.0。

=========================

$ curl -i http://<ip address>index.html
HTTP/1.1 200 OK
Server: thttpd/2.25b 29dec2003
Content-Type: text/html; charset=iso-8859-1
Date: Tue, 04 Aug 2009 07:00:52 GMT
Last-Modified: Tue, 04 Aug 2009 06:58:04 GMT
Accept-Ranges: bytes
Connection: close
Content-Length: 74

<html>
<head><title>blah</title></
head>
<body>Hello There!</body>
</html>


$ curl -i http://<ip address>/cgi-bin/hello
HTTP/1.0 200 OK
Content-type: text/html

Hello there!

=========================

thttpd CGI 甚至无法响应 HTTP HEAD 请求。

$ curl --head http://<ip address>/cgi-bin/hello
HTTP/1.1 501 Not Implemented
Server: thttpd/2.25b 29dec2003
Content-Type: text/html; charset=iso-8859-1
Date: Tue, 04 Aug 2009 07:02:36 GMT
Last-Modified: Tue, 04 Aug 2009 07:02:36 GMT
Accept-Ranges: bytes
Connection: close
Cache-Control: no-cache,no-store

=========================

有没有办法在 CGI 请求上启用 HTTP 1.1?顺便说一句,这是使用 thttpd ver.2.25b。

谢谢,肯尼斯

答案1

众所周知,与 dhttpd 不同,thttpd 支持 CGI,但手册页并未提及文档中请求所支持的 HTTP 级别。摘自 thttpd 手册页:

CGI

   thttpd supports the CGI 1.1 spec.

   In order for a CGI program to be run, its name must match  the  pattern
   specified  either  at  compile  time or on the command line with the -c
   flag.  This is a simple shell-style filename pattern.  You can use * to
   match  any  string  not  including  a  slash, or ** to match any string
   including slashes, or ? to match any single character.   You  can  also
   use  multiple  such  patterns separated by |.  The patterns get checked
   against the filename part of the incoming URL.  Don’t forget  to  quote
   any wildcard characters so that the shell doesn’t mess with them.

   Restricting  CGI  programs to a single directory lets the site adminis‐
   trator review them for security holes, and is strongly recommended.  If
   there  are individual users that you trust, you can enable their direc‐
   tories too.

   If no CGI pattern is specified, neither here nor at compile time,  then
   CGI  programs  cannot  be  run at all.  If you want to disable CGI as a
   security measure, that’s how you do it, just comment out  the  patterns
   in the config file and don’t run with the -c flag.

   Note:  the current working directory when a CGI program gets run is the
   directory that the CGI program lives in.  This isn’t  in  the  CGI  1.1
   spec, but it’s what most other HTTP servers do.

   Relevant   config.h   options:  CGI_PATTERN,  CGI_TIMELIMIT,  CGI_NICE,
   CGI_PATH, CGI_LD_LIBRARY_PATH, CGIBINDIR.

关于 HTTP 1.1 支持的具体问题,我认为在 thttpd 支持论坛上提问可能是最好的解决方法,无需阅读代码。我对 HTTP 1.0 并不感到惊讶,因为它节省了服务器存储页面片段的时间,直到整个页面可用,以便在 HTTP 1.1 标头中正确填写字节数。

当然,在 libhttpd.c 中的例程中,cgi_interpose_output( httpd_conn* hc, int rfd )启动的序列

(void) my_snprintf( buf, sizeof(buf), "HTTP/1.0 %d %s\015\012", status, title );

似乎支持这种观点,但我希望您可能比我更熟悉代码,并且邮件列表中会有对此有详细了解并且可以更明确的人们。

相关内容