[racket] Quitting web servlet apps

From: Nadeem Abdul Hamid (nadeem at acm.org)
Date: Wed Jun 23 15:36:31 EDT 2010

A couple of questions regarding quitting web apps,

1. I start up a servlet so:
    (serve/servlet my-dispatch #:quit? #t ...)
  Now, how come if I use a program like curl/wget to access the "/quit" URL, the server doesn't shut down, but accessing the same URL via a web browser does? Here's the terminal interaction with curl:

$ curl http://localhost:8000/quit
<html><head><title>Server Stopped</title><link rel="stylesheet" href="/error.css" /></head><body><div class="section"><div class="title">Server Stopped</div><p>Return to DrRacket.</p></div></body></html>

... The server continues running. Now if I visit the same url in a browser, it stops after displaying the same HTML above. Here's the log file for the servlet (the two requests look identical):

127.0.0.1 - - [23/Jun/2010:15:25:29 -0400] "GET /quit HTTP/1.1" 200 512
127.0.0.1 - - [23/Jun/2010:15:25:37 -0400] "GET /quit HTTP/1.1" 200 512



2. In general, is there a good way to set up a different URL to stop the server? E.g. suppose I want to set up a "/shutdown" URL that determines first if the current user is properly authenticated, and then shuts down the server. I was playing around putting in a request to "/quit" in the handler for the /shutdown URL: "(get-pure-port (string->url "http://localhost:8000/quit")) ... " but this, like with curl, returns the "Server Stopped" page but doesn't actually stop the server.  How does the DrRacket "Stop" button stop a running web server nicely? I tried doing (break-thread (current-thread)) in the handler for /shutdown, but that didn't quit work either.


Thanks in advance,
--- nadeem



Posted on the users mailing list.