1

我们有一个使用 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可以做到?

真挚地!

4

3 回答 3

1

可能与 EOL 字符有关。

Chunga API docs中,您可以看到read-line *函数需要一个 CR 作为 EOL 标记,这不是 *nixes 的默认值。以下应该使它工作(它适用于我):

(setf chunga:*accept-bogus-eols* t)

编辑:进一步阅读* accept-bogus-eols *我可以明白为什么这是 Chunga 的正常行为:库本身符合 RFC2616 (HTTP 1.1),其中 HTTP 协议的默认 EOL 标记是 CRLF。

于 2012-01-04T02:40:33.937 回答
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"

通过破解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*))))

任何建议表示赞赏!

于 2011-12-28T06:13:38.477 回答
0

关于“合并路径名”的奇怪行为:

* (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”。

真挚地!

于 2012-01-05T06:42:37.243 回答