Skip to content

Instantly share code, notes, and snippets.

@airhorns
Forked from anonymous/core.clj
Last active December 10, 2015 14:28
Show Gist options
  • Save airhorns/4447544 to your computer and use it in GitHub Desktop.
Save airhorns/4447544 to your computer and use it in GitHub Desktop.
(ns snapper.core
(:require [ring.adapter.jetty :as jetty]
[clojure.java.io :as io]
[ring.util.io :as ringio])
(:gen-class))
(defn handler
"Respond with a stream"
[request]
(let [input-stream
(ringio/piped-input-stream
(fn [output-stream]
(try
(.write output-stream 97)
(Thread/sleep 500)
(.write output-stream 97)
(.close output-stream)
(catch Exception e
(println "Caught" (.getMessage e)) "failure")
)
))]
{
:status 200
:headers {}
:body input-stream
}
)
)
(defn -main
[& args]
(jetty/run-jetty handler {:port 8081})
)
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