Skip to content

Commit

Permalink
Fixed local-to-local replication
Browse files Browse the repository at this point in the history
Regression from the conversion to NSURLSession. The CBL_URLProtocol has
to be explicitly registered with the session. This restores the ability
of the replicator to reach URLs served by the router.

Fixes #1292
  • Loading branch information
snej committed Jun 15, 2016
1 parent d456835 commit 25bc191
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
6 changes: 6 additions & 0 deletions Source/CBLRemoteSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ + (NSURLSessionConfiguration*) defaultConfiguration {
config.HTTPShouldSetCookies = NO;
config.URLCache = nil;
config.HTTPAdditionalHeaders = @{@"User-Agent": [CBL_ReplicatorSettings userAgentHeader]};

// Register the router's NSURLProtocol. This allows the replicator to access local databases
// via their internalURLs.
Class cblURLProtocol = NSClassFromString(@"CBL_URLProtocol");
if (cblURLProtocol)
config.protocolClasses = @[cblURLProtocol];
return config;
}

Expand Down
57 changes: 29 additions & 28 deletions Unit-Tests/ReplicatorInternal_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -542,35 +542,36 @@ - (void) test_15_ParseReplicatorProperties {
}
}];

if (NSClassFromString(@"CBLURLProtocol")) {
// Local-to-local replication:
props = $dict({@"source", @"foo"},
{@"target", @"bar"});
AssertEq([dbmgr parseReplicatorProperties: props
toDatabase: &parsedDB
remote: &remote
isPush: &isPush
createTarget: &createTarget
headers: &headers
authorizer: NULL],
404);
props = $dict({@"source", @"foo"},
{@"target", @"bar"}, {@"create_target", $true});
AssertEq([dbmgr parseReplicatorProperties: props
toDatabase: &parsedDB
remote: &remote
isPush: &isPush
createTarget: &createTarget
headers: &headers
authorizer: NULL],
200);
AssertEq(parsedDB, db);
AssertEqual(remote, $url(@"http://lite.couchbase./bar/"));
AssertEq(isPush, YES);
AssertEq(createTarget, YES);
AssertEqual(headers, nil);
}
// Local-to-local replication:
Assert(dbmgr.internalURL);
props = $dict({@"source", db.name},
{@"target", @"bar"});
AssertEq([dbmgr parseReplicatorProperties: props
toDatabase: &parsedDB
remote: &remote
isPush: &isPush
createTarget: &createTarget
headers: &headers
authorizer: NULL],
404);

CBLDatabase* barDB = [dbmgr databaseNamed: @"bar" error: NULL];
Assert(barDB);

AssertEq([dbmgr parseReplicatorProperties: props
toDatabase: &parsedDB
remote: &remote
isPush: &isPush
createTarget: &createTarget
headers: &headers
authorizer: NULL],
200);
AssertEq(parsedDB, db);
AssertEqual(remote, barDB.internalURL);
AssertEq(isPush, YES);
AssertEqual(headers, nil);

// OAuth:
NSDictionary* oauthDict = $dict({@"consumer_secret", @"consumer_secret"},
{@"consumer_key", @"consumer_key"},
{@"token_secret", @"token_secret"},
Expand Down

0 comments on commit 25bc191

Please sign in to comment.