i'm interested in seeing how this progresses ... like how you'd spawn handlers asynchronously to service the requests. was thinking about doing this exercise myself at some point.
On Tue, Feb 16, 2010 at 4:30 PM, Alan Dipert <alan.dip...@gmail.com> wrote: > Hi Matt, > I think what you're looking for is line-seq: > > http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/line-seq > > In your code, if you pass *in* to line-seq, you'll get back a seq of lines > (the request headers). Incidentally, I first ran into line-seq in the > course of writing a Clojure web server as a first project. You can see > line-seq in action on line 52 of this gist, inside the 'handle-request' > function: http://gist.github.com/203329 > > I'm pretty new to Clojure myself so there might be a better way. Hope > this helps, > > Alan > > Excerpts from Matt Culbreth's message of 2010-02-16 16:17:57 -0500: > > Hello Group, > > > > I'm writing a web server in Clojure and I'd love to have a bit of help > > on a function I have. > > > > This function (and at http://gist.github.com/305909) is used to read > > the HTTP request from a client and to then act on it: > > > > (defn handle-request > > [in out] > > (binding [*in* (BufferedReader. (InputStreamReader. in))] > > (let [client-out (OutputStreamWriter. out)] > > (loop [lines []] > > (let [input (read-line)] > > (if > > (= (.length input) 0) > > ;; 0 length line means it's time to serve the > > resource > > (println lines) > > ;; add to the lines vector and keep going > > ;; note it makes the incoming request reversed > > (recur (cons input lines)))))))) > > > > The code works fine; I've left out the bit that actually does > > something and replaced it with a println call. It's not very > > functional feeling though. The loop/recur and the building of a list > > seems very imperative to me. I'd much rather use something from > > clojure.contrib.io, probably using read-lines or something. > > > > Thanks for looking and for any suggestions! > > > > Matt > > > -- > Alan Dipert > http://alan.dipert.org > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en