assuming you are doing this using java servlet.

you may want to look at how compojure does this.

http://github.com/weavejester/compojure/blob/master/src/compojure/http/servlet.clj

it turns the request into a map.

and then various other parts of compojure can do different things
based on the map.

On Tue, Feb 16, 2010 at 4:17 PM, Matt Culbreth <mattculbr...@gmail.com> wrote:
> 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
>
> --
> 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



-- 
Omnem crede diem tibi diluxisse supremum.

-- 
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

Reply via email to