setCookie in Replication doesn't send a cookie

111 views
Skip to first unread message

Constantine Kozak

unread,
Feb 16, 2015, 5:05:30 AM2/16/15
to mobile-c...@googlegroups.com


I want to use Replication with custom auth. As I understand I can get sessionId with my own means (app calls my server which POST to SyncGateway's _session) and then just set a cookie in Replication and it should pass it. I create a replication in a such way:

Replication pullReplication = database.createPullReplication("http://host.com:4984/dbName");
pullReplication.setContinuous(true);
pullReplication.setCookie("SyncGatewaySession", "<SESSION ID VALUE>", "host.com:4984", expireDate, false, false);

and get these:
02-16 05:01:07.370    4706-4746/com.phrazr.android.staging E/RemoteRequest﹕ Got error status: 401 for http://host.com:4984/dbName/_local/d07fc6d8daf6751891ac5d806aaf5a6cf2945960.  Reason: Unauthorized

I checked in a http sniffer - cookies are not sent. The only headers present are: Host=host.com:4984, Accept=multipart/related, application/json and Connection=Keep-Alive.

Am I using setCookie in a wrong way or it's a bug?

Jens Alfke

unread,
Feb 16, 2015, 12:39:44 PM2/16/15
to mobile-c...@googlegroups.com

> On Feb 16, 2015, at 2:05 AM, Constantine Kozak <mak...@gmail.com> wrote:
>
> pullReplication.setCookie("SyncGatewaySession", "<SESSION ID VALUE>", "host.com:4984", expireDate, false, false);

The 3rd parameter is the hostname. It should be “host.com”, with no port. (Cookies aren’t port-specific anyway, surprisingly.)

—Jens

Hideki Itakura

unread,
Feb 16, 2015, 1:27:20 PM2/16/15
to mobile-c...@googlegroups.com
Hi Constanine,

It seems your code is correct. Which version of CBL Android or Java are you using? 1.0.3.1, 1.0.4 or master branch? If you still encounter  the issue, please file the ticket from here, https://github.com/couchbase/couchbase-lite-java-core/issues .

Thanks,
Hideki

setCookie method segnature:
```
/**
     * Sets an HTTP cookie for the Replication.
     *
     * @param name The name of the cookie.
     * @param value The value of the cookie.
     * @param path The path attribute of the cookie.  If null or empty, will use remote.getPath()
     * @param maxAge The maxAge, in milliseconds, that this cookie should be valid for.
     * @param secure Whether the cookie should only be sent using a secure protocol (e.g. HTTPS).
     * @param httpOnly (ignored) Whether the cookie should only be used when transmitting HTTP, or HTTPS, requests thus restricting access from other, non-HTTP APIs.
     */
    @InterfaceAudience.Public
    public void setCookie(String name, String value, String path, long maxAge, boolean secure, boolean httpOnly);
```

Jens Alfke

unread,
Feb 16, 2015, 4:25:53 PM2/16/15
to mobile-c...@googlegroups.com

On Feb 16, 2015, at 10:27 AM, Hideki Itakura <hideki....@gmail.com> wrote:

It seems your code is correct. Which version of CBL Android or Java are you using?

Oops, I didn’t see this was Java. In that case the problem with the code is that the 3rd parameter is the path, which should be left as null (it defaults to the path of the replication’s remote database.)

—Jens

Constantine Kozak

unread,
Feb 16, 2015, 6:24:29 PM2/16/15
to mobile-c...@googlegroups.com
Thanks, setting host to null resolved my issue


On Monday, February 16, 2015 at 2:05:30 AM UTC-8, Constantine Kozak wrote:
Reply all
Reply to author
Forward
0 new messages