You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2023/07/24 20:11:02 UTC

[couchdb] branch add-replicator-user-agent-to-session-requests created (now 91887542b)

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a change to branch add-replicator-user-agent-to-session-requests
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at 91887542b Add "CouchDB-Replicator/..." user agent to replicator /_session requests

This branch includes the following new commits:

     new 91887542b Add "CouchDB-Replicator/..." user agent to replicator /_session requests

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/01: Add "CouchDB-Replicator/..." user agent to replicator /_session requests

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch add-replicator-user-agent-to-session-requests
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 91887542b66e7fb3b1f10285b98ae277072ddf03
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Mon Jul 24 16:05:44 2023 -0400

    Add "CouchDB-Replicator/..." user agent to replicator /_session requests
    
    User the same user agent as we do for all the other replicator requests.
---
 .../include/couch_replicator_api_wrap.hrl            |  3 ++-
 .../src/couch_replicator_auth_session.erl            | 20 ++++++++++++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/couch_replicator/include/couch_replicator_api_wrap.hrl b/src/couch_replicator/include/couch_replicator_api_wrap.hrl
index 0f8213c51..6d6ad527c 100644
--- a/src/couch_replicator/include/couch_replicator_api_wrap.hrl
+++ b/src/couch_replicator/include/couch_replicator_api_wrap.hrl
@@ -11,13 +11,14 @@
 % the License.
 
 
+-define(COUCH_REPLICATOR_USER_AGENT, "CouchDB-Replicator/" ++ couch_server:get_version()).
 
 -record(httpdb, {
     url,
     auth_props = [],
     headers = [
         {"Accept", "application/json"},
-        {"User-Agent", "CouchDB-Replicator/" ++ couch_server:get_version()}
+        {"User-Agent", ?COUCH_REPLICATOR_USER_AGENT}
     ],
     timeout,            % milliseconds
     ibrowse_options = [],
diff --git a/src/couch_replicator/src/couch_replicator_auth_session.erl b/src/couch_replicator/src/couch_replicator_auth_session.erl
index 38fd09b46..a5cfaf190 100644
--- a/src/couch_replicator/src/couch_replicator_auth_session.erl
+++ b/src/couch_replicator/src/couch_replicator_auth_session.erl
@@ -307,7 +307,10 @@ maybe_refresh(#state{next_refresh = T} = State) ->
 -spec refresh(#state{}) -> {ok, #state{}} | {error, term()}.
 refresh(#state{session_url = Url, user = User, pass = Pass} = State) ->
     Body = mochiweb_util:urlencode([{name, User}, {password, Pass}]),
-    Headers0 = [{"Content-Type", "application/x-www-form-urlencoded"}],
+    Headers0 = [
+        {"User-Agent", ?COUCH_REPLICATOR_USER_AGENT},
+        {"Content-Type", "application/x-www-form-urlencoded"}
+    ],
     Headers =
         case State#state.require_valid_user of
             true ->
@@ -535,7 +538,8 @@ cookie_update_test_() ->
                 t_init_state_401_with_require_valid_user(),
                 t_init_state_404(),
                 t_init_state_no_creds(),
-                t_init_state_http_error()
+                t_init_state_http_error(),
+                t_send_replicator_user_agent()
             ]
         }
     }.
@@ -651,6 +655,18 @@ t_init_state_http_error() ->
         ?assertEqual({session_request_failed, SessionUrl, "u", x}, Error)
     end).
 
+t_send_replicator_user_agent() ->
+    ?_test(begin
+        mock_http_cookie_response("Abc"),
+        {ok, State} = maybe_refresh(#state{next_refresh = 0}),
+        ?assertMatch(#state{epoch = 1, cookie = "Abc"}, State),
+        % Headers is the 3rd argument in send_req_direct/7
+        % See https://hexdocs.pm/meck/meck.html#capture-5
+        Headers = meck:capture(first, ibrowse, send_req_direct, '_', 3),
+        UserAgent = proplists:get_value("User-Agent", Headers),
+        ?assertMatch("CouchDB-Replicator/" ++ _, UserAgent)
+    end).
+
 httpdb(Url) ->
     couch_replicator_utils:normalize_basic_auth(#httpdb{url = Url}).