couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chewbra...@apache.org
Subject [3/3] chttpd commit: updated refs/heads/1843-feature-bigcouch-clustered-eventsource-changes-feed to 17268d7
Date Tue, 27 May 2014 23:02:28 GMT
 Support Last-Event-ID header for eventsource changes feeds


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

Branch: refs/heads/1843-feature-bigcouch-clustered-eventsource-changes-feed
Commit: 17268d7bb33bdb634a4f23a28e215a4dd0b76e04
Parents: b6882d1
Author: Russell Branca <chewbranca@apache.org>
Authored: Tue May 27 15:57:32 2014 -0700
Committer: Russell Branca <chewbranca@apache.org>
Committed: Tue May 27 16:02:04 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/17268d7b/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