You can't consume an input-stream twice. You need to store the result
somewhere.

For example:

  (defn handler [request]
    (let [body-str (slurp (:body request))]
      (do-something-to body-str)
      (do-something-else-to body-str)))

Be aware that in production you'll likely want to limit the maximum size of
the stream to avoid malicious users pushing through large amounts of junk
data and using up all the memory in your app. There's a class in the Apache
Commons I/O called BoundedInputStream that might be of use to you.

- James


On 2 March 2014 17:23, action <actioncao2...@gmail.com> wrote:

> how to use slurp?
> first:
> (slurp body)
> and second reuse:
>  (slurp body)
>
> 在 2014年3月3日星期一UTC+8上午12时44分09秒,James Reeves写道:
>>
>> Depending on how large the input is, you could either read it all into
>> memory (e.g. with slurp or similar), or dump it to a temporary file.
>>
>> - James
>>
>>
>> On 2 March 2014 16:18, action <action...@gmail.com> wrote:
>>
>>>  I want to parse the POST body twice,
>>> but in the second place:
>>> org.xml.sax.SAXParseException: Premature end of file.
>>> How should I clone the body render for the second parse?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send
>>> an email to clojure+u...@googlegroups.com.
>>>
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to