diff --git a/awful-sse.meta b/awful-sse.meta deleted file mode 100644 index 99f6e4b..0000000 --- a/awful-sse.meta +++ /dev/null @@ -1,8 +0,0 @@ -;; -*- Scheme -*- - -((synopsis "Server-Sent Events module for Awful") - (author "Arthur Maciel") - (category web) - (license "BSD") - (depends awful spiffy intarweb) - (test-depends test server-test uri-common http-client)) diff --git a/awful-sse.setup b/awful-sse.setup deleted file mode 100644 index 0a215f3..0000000 --- a/awful-sse.setup +++ /dev/null @@ -1,9 +0,0 @@ -;; -*- Scheme -*- - -(compile -s -O2 awful-sse.scm -j awful-sse) -(compile -s -O2 awful-sse.import.scm) - -(install-extension - 'awful-sse - '("awful-sse.so" "awful-sse.import.so") - '((version "0.1"))) diff --git a/awful.sse.egg b/awful.sse.egg new file mode 100644 index 0000000..63aa4d3 --- /dev/null +++ b/awful.sse.egg @@ -0,0 +1,9 @@ +;; -*- mode: scheme -*- +((author "Arthur Maciel") + (synopsis "Server-Sent Events module for Awful") + (category web) + (license "BSD") + (dependencies awful spiffy intarweb) + (test-dependencies test server-test uri-common http-client) + (components + (extension awful.sse))) diff --git a/awful-sse.release-info b/awful.sse.release-info similarity index 100% rename from awful-sse.release-info rename to awful.sse.release-info diff --git a/awful-sse.scm b/awful.sse.scm similarity index 67% rename from awful-sse.scm rename to awful.sse.scm index 6238957..1ccddf8 100644 --- a/awful-sse.scm +++ b/awful.sse.scm @@ -24,32 +24,37 @@ ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -(module awful-sse - +(module (awful sse) + (define-page/sse send-sse-data send-sse-retry) - - (import scheme chicken data-structures extras posix) - (use awful spiffy intarweb) - + + (import scheme + (chicken base) + (chicken keyword) + (chicken string) + ;;data-structures extras posix + awful spiffy intarweb) + (define (add-sse-resource! sse-path sse-proc vhost-root-path client-path) (add-resource! sse-path - (or vhost-root-path (root-path)) - (lambda (#!optional given-path) - (let ((accept (header-values 'accept - (request-headers (current-request))))) - ;; If client's EventSource (JS code) requested SSE page... - (if (memq 'text/event-stream accept) - ;;...complete handshake & keep connection alive with 'sse-proc'. + (or vhost-root-path (root-path)) + (lambda (#!optional given-path) + (let ((accept (header-values 'accept + (request-headers (current-request))))) + ;; If client's EventSource (JS code) requested SSE page... + (if (memq 'text/event-stream accept) + ;;...complete handshake & keep connection alive with 'sse-proc'. (lambda () - (with-headers '((content-type text/event-stream) - (cache-control no-cache) - (connection keep-alive)) - (lambda () - (write-logged-response) - (sse-proc)))) - (redirect-to client-path)))) - 'GET)) - + (with-headers '((content-type text/event-stream) + (cache-control no-cache) + (connection keep-alive)) + (lambda () + (write-logged-response) + (sse-proc)))) + (redirect-to client-path)))) + 'GET + #f)) + (define (define-page/sse path contents sse-path sse-proc #!rest rest) (apply define-page (append (list path contents) rest)) (add-sse-resource! sse-path sse-proc (get-keyword vhost-root-path: rest) path)) @@ -57,13 +62,13 @@ (define (write-body data) (display data (response-port (current-response))) (finish-response-body (current-response))) - + (define (send-sse-data data #!key event id) (let ((msg (conc (if id (conc "id: " id "\n") "") (if event (conc "event: " event "\n") "") "data: " data "\n\n"))) (write-body msg))) - + (define (send-sse-retry retry) (write-body (conc "retry: " retry "\n\n"))) diff --git a/awful-sse.wiki b/awful.sse.wiki similarity index 100% rename from awful-sse.wiki rename to awful.sse.wiki diff --git a/tests/client.scm b/tests/client.scm index c2f64c2..5c6a23f 100644 --- a/tests/client.scm +++ b/tests/client.scm @@ -1,4 +1,4 @@ -(use awful-sse) +(import (awful sse)) (define (sse-proc) (send-sse-data "sse")) diff --git a/tests/run.scm b/tests/run.scm index fa8e2ca..7c4d5ab 100644 --- a/tests/run.scm +++ b/tests/run.scm @@ -1,4 +1,6 @@ -(use awful http-client intarweb uri-common server-test test) +(import (chicken base) + (chicken io) + awful http-client intarweb uri-common server-test test) (awful-apps (list "client.scm"))