Created
January 3, 2013 21:11
-
-
Save anonymous/4447300 to your computer and use it in GitHub Desktop.
troubleshooting streaming responses with ring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns snapper.core | |
(:require [ring.adapter.jetty :as jetty] | |
[clojure.java.io :as io] | |
[ring.util.io :as ringio]) | |
(:import [java.io PipedOutputStream PipedInputStream PrintWriter]) | |
(:gen-class)) | |
(defn handler | |
"Respond with a stream" | |
[request] | |
(let [input-stream | |
(ringio/piped-input-stream | |
(fn [output-stream] | |
(.write output-stream "Hello") | |
(Thread/sleep 500) | |
(.write output-stream "World") | |
(.close output-stream) | |
))] | |
{ | |
:status 200 | |
:headers {} | |
:body input-stream | |
} | |
) | |
) | |
(defn -main | |
[& args] | |
(jetty/run-jetty handler {:port 8081}) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
oration ~/C/snapper (master*) ➜ curl -v localhost:8081 | |
* About to connect() to localhost port 8081 (#0) | |
* Trying ::1... | |
* connected | |
* Connected to localhost (::1) port 8081 (#0) | |
> GET / HTTP/1.1 | |
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5 | |
> Host: localhost:8081 | |
> Accept: */* | |
> | |
< HTTP/1.1 200 OK | |
< Date: Thu, 03 Jan 2013 21:10:41 GMT | |
< Content-Length: 0 | |
< Server: Jetty(7.6.1.v20120215) | |
< | |
* Connection #0 to host localhost left intact | |
* Closing connection #0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment