couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chewbra...@apache.org
Subject chttpd commit: updated refs/heads/1843-feature-bigcouch-clustered-eventsource-changes-feed to be1643b
Date Wed, 28 May 2014 22:38:12 GMT
Repository: couchdb-chttpd
Updated Branches:
  refs/heads/1843-feature-bigcouch-clustered-eventsource-changes-feed 17268d7bb -> be1643b43
(forced update)


Support Last-Event-ID header for eventsource changes feeds

COUCHDB-1852


Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/be1643b4
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/be1643b4
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/be1643b4

Branch: refs/heads/1843-feature-bigcouch-clustered-eventsource-changes-feed
Commit: be1643b43106e30ae17e7aac92680c57be7018de
Parents: b6882d1
Author: Damjan Georgievski <gdamjan@gmail.com>
Authored: Sat Jul 20 15:46:04 2013 +0100
Committer: Russell Branca <chewbranca@apache.org>
Committed: Wed May 28 15:32:02 2014 -0700

----------------------------------------------------------------------
 src/chttpd_db.erl | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/be1643b4/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 5c1c24d..dada7d8 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -1211,7 +1211,7 @@ parse_doc_query(Req) ->
     end, #doc_query_args{}, chttpd:qs(Req)).
 
 parse_changes_query(Req) ->
-    lists:foldl(fun({Key, Value}, Args) ->
+    ChangesArgs = lists:foldl(fun({Key, Value}, Args) ->
         case {string:to_lower(Key), Value} of
         {"feed", _} ->
             Args#changes_args{feed=Value};
@@ -1240,7 +1240,21 @@ parse_changes_query(Req) ->
         _Else -> % unknown key value pair, ignore.
             Args
         end
-    end, #changes_args{}, couch_httpd:qs(Req)).
+    end, #changes_args{}, couch_httpd:qs(Req)),
+    %% if it's an EventSource request with a Last-event-ID header
+    %% that should override the `since` query string, since it's
+    %% probably the browser reconnecting.
+    case ChangesArgs#changes_args.feed of
+        "eventsource" ->
+            case couch_httpd:header_value(Req, "last-event-id") of
+                undefined ->
+                    ChangesArgs;
+                Value ->
+                    ChangesArgs#changes_args{since=list_to_integer(Value)}
+            end;
+        _ ->
+            ChangesArgs
+    end.
 
 extract_header_rev(Req, ExplicitRev) when is_binary(ExplicitRev) or is_list(ExplicitRev)->
     extract_header_rev(Req, couch_doc:parse_rev(ExplicitRev));


Mime
View raw message