fukamachi / caveman

Lightweight web application framework for Common Lisp.
http://8arrow.org/caveman/
782 stars 63 forks source link

How to specify Content-Type ? #14

Open rapenne-s opened 11 years ago

rapenne-s commented 11 years ago

I have some problems related with Apache + mod_lisp because not content-type is defined, or serving RSS feed not served as a XML or stuff like that.

How can I specify the content-type of a response ? I have seen that it is possible to do it in Clack, but I don't understand how to access it from caveman.

fukamachi commented 11 years ago

You can use caveman:*response* in controller functions. It is a response object of caveman.response:<response> which is a subclass of clack.response:.

(setf (clack.response:headers *response* :content-type) "application/rss+xml")
rapenne-s commented 11 years ago

Thank you for your precise answer, it works great !

Would you merge a pull request if I add some documentation to caveman ?

fukamachi commented 11 years ago

Sure :)

I'm aware that the documentation isn't enough. I'll appreciate your contribution.

vityok commented 11 years ago

Hi, I've got two ideas:

@url GET "/names.json"
(defun get-names-json (params)
  @content-type "text/json"
  ....)

But let the setf way of altering the content type for special cases.

Thanks!

vityok commented 11 years ago

As far as I understand this annotation might be defined somewhat like:

(defannotation content-type (mime)
  (:arity 1)
  `(setf (clack.response:headers *response* :content-type) ,mime))

Please include it (if it is correct) and you find it useful as well. Thanks!

rapenne-s commented 11 years ago

This would be a very nice addition !