Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit b475596

Browse files
authored
Merge pull request #417 from cloudant/415-cookie-url
Correctly perform cookie authentication
2 parents 436d30a + c2ab40e commit b475596

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- [FIXED] Issue performing cookie authentication in version 1.1.3.
3+
14
# 1.1.3 (2016-11-22)
25
- [FIXED] Incorrect message output from parameter `null` or empty checks.
36
- [FIXED] Issue where replications would error if the server returned missing revisions.

cloudant-sync-datastore-core/src/main/java/com/cloudant/sync/replication/ReplicatorBuilder.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,27 @@ private URI addCookieInterceptorIfRequired(URI uri) {
7070
if (uri.getUserInfo() != null) {
7171
String[] parts = uri.getUserInfo().split(":");
7272
if (parts.length == 2) {
73-
CookieInterceptor ci = new CookieInterceptor(parts[0], parts[1], uri.toString());
73+
74+
String path = uri.getRawPath();
75+
int index = path.lastIndexOf("/");
76+
if (index == path.length() - 1) {
77+
// we need to go back one
78+
path = path.substring(0, index);
79+
index = path.lastIndexOf("/");
80+
}
81+
82+
path = path.substring(0, index);
83+
84+
URI baseURI;
85+
86+
try {
87+
baseURI = new URI(uriProtocol, null, uriHost, uriPort, path, null, null);
88+
} catch (URISyntaxException e) {
89+
throw new RuntimeException(e);
90+
}
91+
92+
93+
CookieInterceptor ci = new CookieInterceptor(parts[0], parts[1], baseURI.toString());
7494
requestInterceptors.add(ci);
7595
responseInterceptors.add(ci);
7696
}

0 commit comments

Comments
 (0)