couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From benoitc <...@git.apache.org>
Subject [GitHub] couchdb pull request: Use cookie authentication during replication
Date Tue, 11 Mar 2014 10:03:37 GMT
Github user benoitc commented on a diff in the pull request:

    https://github.com/apache/couchdb/pull/172#discussion_r10467062
  
    --- Diff: src/couch_replicator/src/couch_replicator_httpc.erl ---
    @@ -131,6 +171,90 @@ process_stream_response(ReqId, Worker, HttpDb, Params, Callback)
->
         end.
     
     
    +process_stream_response_headers(ReqId, Code, Headers, Worker, HttpDb, Params, Callback)
->
    +    StreamDataFun = fun() ->
    +        stream_data_self(HttpDb, Params, Worker, ReqId, Callback)
    +    end,
    +    ibrowse:stream_next(ReqId),
    +    try
    +        Ret = Callback(Code, Headers, StreamDataFun),
    +        release_worker(Worker, HttpDb),
    +        clean_mailbox_req(ReqId),
    +        Ret
    +    catch throw:{maybe_retry_req, Err} ->
    +        clean_mailbox_req(ReqId),
    +        maybe_retry(Err, Worker, HttpDb, Params, Callback)
    +    end.
    +
    +
    +maybe_start_new_session(HttpDb) ->
    +    case need_new_session(HttpDb) of
    +    false -> false;
    +    true -> start_new_session(HttpDb)
    +    end.
    +
    +
    +maybe_start_new_session(HttpDb, Worker) ->
    +    case need_new_session(HttpDb) of
    +    false -> false;
    +    true -> start_new_session(HttpDb, Worker)
    +    end.
    +
    +
    +need_new_session(#httpdb{credentials = undefined}) ->
    +    false;
    +
    +need_new_session(#httpdb{credentials = Credentials}) ->
    +    case ets:lookup(Credentials, cookie) of
    +    [] ->
    +        true;
    +    [{cookie, _, UpdatedAt}] ->
    +        %% As we don't know when the cookie will expire, we just decide
    +        %% that we want a new session if the current one is older than
    +        %% one minute.
    +        OneMinute = 60 * 1000000, % microseconds
    --- End diff --
    
    On Tue, Mar 11, 2014 at 10:56 AM, Klaus Trainer <notifications@github.com>wrote:
    
    > In src/couch_replicator/src/couch_replicator_httpc.erl:
    >
    > > +    true -> start_new_session(HttpDb, Worker)
    > > +    end.
    > > +
    > > +
    > > +need_new_session(#httpdb{credentials = undefined}) ->
    > > +    false;
    > > +
    > > +need_new_session(#httpdb{credentials = Credentials}) ->
    > > +    case ets:lookup(Credentials, cookie) of
    > > +    [] ->
    > > +        true;
    > > +    [{cookie, _, UpdatedAt}] ->
    > > +        %% As we don't know when the cookie will expire, we just decide
    > > +        %% that we want a new session if the current one is older than
    > > +        %% one minute.
    > > +        OneMinute = 60 * 1000000, % microseconds
    >
    > @benoitc <https://github.com/benoitc> I'm sorry, I don't see how TS - Nowcould
relate to the expiry time that's configured on the remote server.
    >
    >
    > Well when you get the expires times in the cookie and compare it to the
    current hour on your machine you know the delay in which the cookie is
    supposed to expire. So either you check against the cookie expires times
    each time, or set a timer to remove it from the ets which will trigger the
    401 the next time ou try to authenticate. In other cases you will have this
    401 anyway.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message