我们有一个使用python开发的CGI应用程序,可以轻松地托管在erlang YAWS中:
>cat ~/yaws.conf
...
<server 192.168.1.2>
port = 8000
listen = 0.0.0.0
docroot = /media/G/www/qachina/
access_log = false
appmods = <cgi-bin, yaws_appmod_cgi>
</server>
...
现在我们要在lisp Web服务器中托管应用程序。也许hunchentoot可以做到吗?
此致!
答案 0 :(得分:1)
可能与EOL角色有关。
从Chunga API docs,您可以看到 读取行 * 函数需要CR作为EOL标记,这不是* nixes的默认值。以下应该使它工作(它适用于我):
(setf chunga:*accept-bogus-eols* t)
编辑:进一步阅读 * accept-bogus-eols 的描述* 我可以看出为什么这是Chunga的正常行为:库本身符合RFC2616( HTTP 1.1)其中HTTP协议的默认EOL标记是CRLF。
答案 1 :(得分:0)
我已经安装了hunchentoot-cgi并对其进行了测试。以下是一个简单的python脚本文件:
>cat cgi-bin/nav.py
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
print "Content-type: text/html\n\n"
print """from Python"""
当我访问http://127.0.0.1:8000/cgi-bin/nav.py时,hunchentoot报告:
11111111111111111
**End of file, but expected #\Newline.**
[2011-12-28 13:35:16 [ERROR]] error in handle-cgi-script from URL /cgi-bin/nav.py
127.0.0.1 - [2011-12-28 13:35:16] "GET /cgi-bin/nav.py HTTP/1.1" 200 - "-"
"Opera/9.80 (X11; FreeBSD 8.2-RELEASE i386; U; zh-cn) Presto/2.10.229 Version/11.60"
通过hackiing hunchentoot-cgi.lisp,我发现函数“handle-cgi-script”报告错误:
(handler-case
(with-input-from-program (in path nil env)
(format t "11111111111111111~%")
(chunga:with-character-stream-semantics
(loop for line = (chunga:read-line* in)
until (equal line "")
do
(format t "22222222222222222:~A~%" line)
(destructuring-bind (key val)
(ppcre:split ": " line :limit 2)
(setf (hunchentoot:header-out key) val))
(format t "22222222222222222~%")))
(format t "33333333333333333~%")
(let ((out (flexi-streams:make-flexi-stream
(tbnl:send-headers)
:external-format tbnl::+latin-1+)))
(copy-stream in out 'character))
(format t "33333333333333333~%"))
(error (error)
(format t "~A~%" error)
(tbnl:log-message* :error "error in handle-cgi-script from URL ~A"
(tbnl:request-uri*))))
任何建议都表示赞赏!
答案 2 :(得分:0)
关于“merge-pathnames”的奇怪行为:
* (merge-pathnames "nav.py" "/media/E/myapp/cgi-bin/")
#P"/media/E/myapp/cgi-bin/nav.py"
它在SBCL REPL中正常工作。但是,当黑客攻击“create-cgi-dispatcher-and-handler”时,我添加以下几行:
(defun create-cgi-dispatcher-and-handler (uri-prefix base-path &optional content-type)
;...
(format t "SName=~A SPath=~A BPath=~A~% the path is ~A~%" script-name script-path base-path (merge-pathnames script-path base-path))
;...
调用如下:
(pushnew (hunchentoot-cgi::create-cgi-dispatcher-and-handler
"/cgi-bin/"
(make-pathname :name "cgi-bin/" :type nil :version nil :defaults *this-file*)
) *dispatch-table* :test #'equal)
然后访问http://127.0.0.1:8000/cgi-bin/nav.py,报告:
SName=/cgi-bin/nav.py SPath=nav.py BPath=/media/E/myapp/cgi-bin/
the path is /media/E/myapp/nav.py
简而言之:
(merge-pathnames“nav.py”“/ media / E / myapp / cgi-bin /”)在REPL中返回#P“/media/E/myapp/cgi-bin/nav.py”。但它在hunchentoot-cgi.lisp中返回“/media/E/myapp/nav.py”。
此致!