0

hunchentoot-cgi 现在基本上可以与 hunchentoot-1.2.2 一起使用,但需要进行一些修改:

  1. #'handle-cgi-script,替换:external-format tbnl::+latin-1+:external-format tbnl::+utf-8+
  2. 正如 WhiteCat 建议的那样,使用#'make-pathname如下:

    (pushnew (hunchentoot-cgi::create-cgi-dispatcher-and-handler
              "/cgi-bin/"
              (make-pathname :directory '(:absolute "media" "E"
                                                    "myapp" "cgi-bin")))
             dispatch-table :test #'equal)
    

但是,我不明白为什么python脚本无法获取POSTed参数,即访问时http://127.0.0:8000/cgi-bin/login.py?cmd=view,login.py可以成功获取参数cmd的值,但是当通过以下表单发布时,login.py无法获取所有发布的值(无论是否隐藏):

<html><body>
  <form method='POST' action='cgi-bin/login.py'>
    <input type='text' name='userid'>
    <input type='password' name='userpwd'>
    <input type='submit' value='Login'>
    <input type='hidden' name='cmd' value='view'>
  </form>
</body></html>

我猜 hunchentoot-cgi 没有根据环境将发布的参数传递给 python 脚本:

  • GET http://127.0.0.1:8000/cgi-bin/nav.py?userid=xyz&cmd=view
    传递给python脚本的环境是:

    (SERVER_SOFTWARE=hunchentoot/1.2.2
     SERVER_NAME=127.0.0.1 GATEWAY_INTERFACE=CGI/1.1
     SERVER_PROTOCOL=HTTP/1.1 SERVER_PORT=8000 REQUEST_METHOD=GET
     CONTENT_TYPE=text/html CONTENT_LENGTH=NIL
     SCRIPT_NAME=/cgi-bin/nav.py QUERY_STRING=userid=xyz&cmd=view
     REMOTE_ADDR=127.0.0.1 HTTP_HOST=NIL
     REQUEST_URI=/cgi-bin/nav.py?userid=xyz&cmd=view SERVER_ADDR=NIL
     HTTP_USER_AGENT=Mozilla/5.0 (X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1
     HTTP_REFERER=http://127.0.0.1:8000/)
    
  • 邮寄到/cgi-bin/nav.py

    (SERVER_SOFTWARE=hunchentoot/1.2.2
     SERVER_NAME=127.0.0.1 GATEWAY_INTERFACE=CGI/1.1
     SERVER_PROTOCOL=HTTP/1.1 SERVER_PORT=8000 REQUEST_METHOD=POST
     CONTENT_TYPE=text/html CONTENT_LENGTH=NIL
     POST_PARAMETERS=((userid . xyz) (userpwd . 123) (cmd . view))
     SCRIPT_NAME=/cgi-bin/nav.py QUERY_STRING=NIL REMOTE_ADDR=127.0.0.1     
     HTTP_HOST=NIL REQUEST_URI=/cgi-bin/nav.py SERVER_ADDR=NIL
     HTTP_USER_AGENT=Mozilla/5.0 (X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1
    

我认为“CONTENT_LENGTH=NIL”是错误的,不是吗?

请大神指点一下,谢谢!

4

2 回答 2

0

After messy hacking of hunchentoot-cgi.lisp, it works now. However, wish it is helpful for Cyrus Harmon (http://cyrusharmon.org/blog) to release the next canonical version.

>diff cgi.lisp /media/E/RnD/clisp/hunchentoot-cgi/hunchentoot-cgi.lisp
71c71
<   (let ((time (or (file-write-date path) (get-universal-time))) (query-string (content-length nil))
---
>   (let ((time (or (file-write-date path) (get-universal-time))))
77,83d76
< (if (member (request-method *request*) *methods-for-post-parameters* :test #'eq)
<     (progn
<         (setq query-string (format nil "~{~A~^&~}" (mapcar (lambda (x) (format nil "~A=~A" (car x) (tbnl:url-encode (cdr x)))) (tbnl:post-parameters*))))
<         (setq content-length (parse-integer (header-in :content-length *request*)))
<     )
<     (setq query-string (tbnl:query-string*)))
< 
87c80,81
<                       . ,(format nil "hunchentoot/~A" hunchentoot-asd:*hunchentoot version*))
---
>                       . (format nil "hunchentoot/~A"
>                                 hunchentoot-asd:*hunchentoot-version*))
97c91,92
<                     #+nil ("REMOTE_HOST" . "FIXME!")
---
>                      ("QUERY_STRING" . ,(tbnl:query-string*))
>                      #+nil ("REMOTE_HOST" . "FIXME!")
101,106c96
<                      ("PATH" . ,(sb-unix::posix-getenv "PATH"))
<                      ("QUERY_STRING" . ,query-string)
<                      ("CONTENT_TYPE" . ,(header-in :content-type *request*))
<                      ("CONTENT_LENGTH" . ,content-length)
<                      ;("HTTP_COOKIE" . ,(tbnl:cookies-out*))
<                      ("HTTP_COOKIE" . "userid=xxx")
---
>                          
112,113c102,103
<                      ("HTTP_REFERER" . ,(tbnl:referer))))))
< (format t "ENV is ~A~%" env)
---
>                      ("HTTP_REFERER" . ,(tbnl:referer))))))      
>       
125c115
<           :external-format tbnl::+utf-8+)))
---
>           :external-format tbnl::+latin-1+)))                   
128d117
< (format t "ERROR: ~A~%" error)                   ("HTTP_REFERER" . (tbnl:referer))))))
< (format t "ENV is ~A~%" env)

Sincerely!

于 2012-01-13T02:14:57.643 回答
0

旧版本的 hunchentoot-cgi 根本不支持 CGI 数据。如果仍然没有为您解决,请尝试 0.3 或更高版本并在 github 上提交问题。

于 2014-01-16T17:23:35.723 回答