-
Notifications
You must be signed in to change notification settings - Fork 113
Supports Server Sent Events (SSE) #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Learn from Go lang Hijack, the APIs of long polling (#36) & Server Sent Events (SSE) will have the consistent form. For Clojure (defn hijack!
"Hijack a nginx request and return a server channel.
After being hijacked, the ring handler's result will be ignored.
If ignore-nginx-filter? is true all data output to channel won't be filtered
by any nginx HTTP header/body filters such as gzip filter, chucked filter, etc.
We can use this function to implement long poll / Server Sent Events (SSE) easily."
[^NginxRequest req ignore-nginx-filter?])
(defprotocol HttpServerChannel
(close! [ch]
"Asynchronously close the channel. If there's remaining data to send it won't block
current thread and will flush data on the background asynchronously and later close the channel safely")
(send! [ch data flush? last?]
"Asynchronously send data to channel without blocking current thread.
data can be byte[], String, or ByteBuffer
If flush? is false it will put data into buffers chain eitherwise it will write data to network.
If close? is true it will close channel after all data are sent.
")
(send-header! [ch status headers flush? last?]
"Asynchronously send HTTP status & headers to channel.
status is a integer for HTTP status code, headers is a HTTP headers map.
If flush? is false it will put data into buffers chain eitherwise it will write data to network.
If close? is true it will close channel after all data are sent.")
(send-response! [ch resp]
"Asynchronously send a complete HTTP response to channel and close channel after all data are sent.
resp is a ring Response Map, e.g. {:status 200, headers {\"Content-Type\" \"text/html\"}, :body \"Hello, Nginx-Clojure!\" } .
")
(on-close! [ch attachment listener]
"Add a close event listener.
attachement is a object which will be passed to listener when close event happens
listener is a function like (fn[attachement] ... )")
) For Java/Groovy public interface NginxHandler {
/*
* If ignoreFilter is true all data output to channel won't be filtered
by any nginx HTTP header/body filters such as gzip filter, chucked filter, etc.
*/
public NginxHttpServerChannel hijack(NginxRequest req, boolean ignoreFilter);
} public class NginxHttpServerChannel {
public <T> void addListener(ChannelListener<T> listener, T data) ;
/**
* If message is null when flush is true it will do flush, when last is true it will close channel.
*/
public void send(byte[] message, int off, int len, boolean flush, boolean last) ;
public void send(String message, boolean flush, boolean last) ;
public void send(ByteBuffer message, boolean flush, boolean last) ;
public <K, V> void sendHeader(long status, Collection<Map.Entry<K, V>> headers, boolean flush, boolean last) ;
public void sendResponse(Object resp) ;
public void close() ; |
more comments about
|
xfeep
added a commit
that referenced
this issue
Sep 2, 2014
xfeep
added a commit
that referenced
this issue
Sep 2, 2014
xfeep
added a commit
that referenced
this issue
Sep 2, 2014
xfeep
added a commit
that referenced
this issue
Sep 3, 2014
This issue was closed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More details can be found from http://www.w3.org/TR/eventsource/ .
We'll provide related APIs to support server side SSE.
The text was updated successfully, but these errors were encountered: