hunchentoot 可以托管 CGI 应用程序吗?

发布于 2024-12-07 11:01:16 字数 371 浏览 0 评论 0原文

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

真挚地!

We have a CGI application developed using python, which can be hosted in erlang YAWS easily:

>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>
...

Now we want to host the application in a lisp web server. Maybe hunchentoot can do it ?

Sincerely!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

逆夏时光 2024-12-14 11:01:16

可能与 EOL 角色有关。

Chunga API 文档,您可以看到读取行* 函数需要 CR 作为 EOL 标记,这不是 *nixes 的默认设置。以下应该使它工作(它对我有用):

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

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

Probably something to do with EOL characters.

From Chunga API docs, you can see the read-line* function expects a CR as EOL marker, which is not the default for *nixes. The following should make it work (it works for me):

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

EDIT: further reading the description of *accept-bogus-eols* I can see why this is the normal behavior of Chunga: the library itself conforms to RFC2616 (HTTP 1.1) in which the HTTP protocol's default EOL marker is CRLF.

水溶 2024-12-14 11:01:16

我已经安装了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*))))

任何建议表示赞赏!

I have installed hunchentoot-cgi and tested it. The following is a simple python script file:

>cat cgi-bin/nav.py
#!/usr/local/bin/python
# -*- coding: utf-8 -*- 

print "Content-type: text/html\n\n"
print """from Python"""

when i visited http://127.0.0.1:8000/cgi-bin/nav.py, hunchentoot reported:

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"

By hackiing hunchentoot-cgi.lisp, i found the function "handle-cgi-script" reported the error:

 (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*))))

Any suggestion is appreciated!

傲世九天 2024-12-14 11:01:16

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

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

真挚地!

Strange behavior about "merge-pathnames":

* (merge-pathnames  "nav.py" "/media/E/myapp/cgi-bin/")
#P"/media/E/myapp/cgi-bin/nav.py"

it works normally in SBCL REPL. However, when hacking "create-cgi-dispatcher-and-handler", i add the following lines:

(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))
;...

Calling it as below:

(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)

Then visiting http://127.0.0.1:8000/cgi-bin/nav.py, it reports:

SName=/cgi-bin/nav.py SPath=nav.py BPath=/media/E/myapp/cgi-bin/
the path is /media/E/myapp/nav.py

In a short word:

(merge-pathnames "nav.py" "/media/E/myapp/cgi-bin/") returns #P"/media/E/myapp/cgi-bin/nav.py" in REPL. But it returns "/media/E/myapp/nav.py" in hunchentoot-cgi.lisp.

Sincerely!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文