/src/aserve-patch.lisp

http://github.com/mtravers/wuwei · Lisp · 68 lines · 38 code · 8 blank · 22 comment · 0 complexity · d0cf888c851017d56d0c149747bb47da MD5 · raw file

  1. (in-package :net.aserve)
  2. #| No longer loaded by default.
  3. Fixes a bug in portableaserve. Modern browsers return headers like this:
  4. Content-type: application/x-www-form-urlencoded; charset=utf-8
  5. The patch below makes aserve ignore the semicolon and following text.
  6. Kudos to David Sobeck for figuring this out.
  7. HAS BEEN FIXED in more recent versions of aserve (+++ conditionalize properly) |#
  8. (defun header-first-field (s)
  9. (let ((sep (position #\; s)))
  10. (if sep
  11. (subseq s 0 sep)
  12. s)))
  13. (defmethod request-query ((req http-request) &key (post t) (uri t)
  14. (external-format
  15. *default-aserve-external-format*))
  16. ;; decode if necessary and return the alist holding the
  17. ;; args to this url. In the alist items the value is the
  18. ;; cdr of the alist item.
  19. ;;
  20. ;; If uri is true then we look for query information in the uri
  21. ;; (following a question mark)
  22. ;; If post is true and this is a post request then we look for
  23. ;; query information in the body of the query.
  24. ;; If both are true (and this is a post) then we look both places.
  25. ;;
  26. ;;
  27. (let ((alist (request-query-alist req))
  28. (signature (cons post uri)))
  29. (if* (not (eq alist :empty))
  30. then (let ((given-sig (getf (request-reply-plist req)
  31. 'request-query-sig)))
  32. (if* (equal given-sig signature)
  33. then ; same args as before, cached value is legit
  34. (return-from request-query alist))))
  35. (let (res)
  36. (if* uri
  37. then (let ((arg (uri-query (request-uri req))))
  38. (if* arg
  39. then (setq res (form-urlencoded-to-query
  40. arg
  41. :external-format external-format)))))
  42. (if* post
  43. then (if* (and (eq (request-method req) :post)
  44. (equal (header-first-field (header-slot-value req :content-type))
  45. "application/x-www-form-urlencoded")
  46. )
  47. then (setf res
  48. (append res
  49. (form-urlencoded-to-query
  50. (get-request-body req)
  51. :external-format external-format)))))
  52. (setf (getf (request-reply-plist req) 'request-query-sig)
  53. signature)
  54. (setf (request-query-alist req) res))))
  55. ;;; The default value for this doesn't actually seem to work.
  56. ;;;; This doesn't effect anything in WuWei except unit tests.
  57. (setq net.aserve.client::cookie-separator "; ")