You use Mongrel??™s response method to respond with a 200 status code, which
means success. You could return other error codes if necessary, of course, such as 404 if a
file isn??™t found or 501 if an internal server error occurs. Next, you set the Content-Type
header, which specifies the type of content you??™re sending, to text/xml. If your page is
viewed with a web browser, this will affect how the page is displayed. Finally, it calls the
to_xml method of your StocksList instance to render your list of stocks as XML, and then
writes that to the output stream, which, in turn, sends it to the client requesting the
information.
nTip A Mongrel handler like the one in Listing 9-1 can be used as a very simple, operating systemindependent
way to perform interprocess communication. For example, you could have a graphical interface
that processed large audio files. You could use a shell script to actually process the files, and then use wget
or curl (both of which download files or web pages from web servers) to trigger a refresh of the graphical
display.
Pages:
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259