Exporting Files and Images

The previous examples have shown how CL-HTTP can create Web pages generated dynamically by Lisp routines. But it can also create URLs from static HTML files, images, and other types of file, just like conventional Web servers. Here's a quick overview of how you do this.

Text files

This is the simplest example; you just specify the pathname of the text file you want to export, and the URL you want to use:

(export-url "http://localhost:8000/robots.txt"
            :text-file
            :pathname "robots.txt")

HTML files

Why would you want to include static Web pages when you can generate them dynamically? Anyway, in case you need to here's how:

(export-url "http://localhost:8000/help.html"
            :html-file
            :pathname "help.html")

Images

You can either export a single image file, or a directory of image files. Here's an example of exporting a single image:

(export-url "http://localhost:8000/favicon.ico"
            :ico-image
            :pathname "/images/favicon.ico")
And here's an image directory. All the image types that CL-HTTP knows about are exported:
(export-url "http://localhost:8000/images/"
            :image-directory
            :pathname "/images/")

Directories

The most general way of exporting files is to export a whole directory:

(export-url "http://localhost:8000/data/"
            :directory
            :pathname "/mydata/"
            :recursive-p t)

Here we've included the option recursive-p t to specify that all the subdirectories should be exported too. Note that although this is the most general option it's also the least secure; where possible you should use the most restrictive export option possible to avoid accidentally exposing your internal files to the Web.


blog comments powered by Disqus