Skip to content

Commit 66c7a7d

Browse files
committed
fix 301 redirect on https
1 parent 466c849 commit 66c7a7d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/main/java/com/uid2/operator/store/CloudSyncOptOutStore.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class CloudSyncOptOutStore implements IOptOutStore {
5353
private final String remoteApiHost;
5454
private final String remoteApiPath;
5555
private final String remoteApiBearerToken;
56+
private final boolean remoteApiSsl;
5657

5758
public CloudSyncOptOutStore(Vertx vertx, ICloudStorage fsLocal, JsonObject jsonConfig, String operatorKey, Clock clock) throws MalformedURLException {
5859
this.fsLocal = fsLocal;
@@ -61,7 +62,9 @@ public CloudSyncOptOutStore(Vertx vertx, ICloudStorage fsLocal, JsonObject jsonC
6162
String remoteApi = jsonConfig.getString(Const.Config.OptOutApiUriProp);
6263
if (remoteApi != null) {
6364
URL url = new URL(remoteApi);
64-
this.remoteApiPort = -1 == url.getPort() ? 80 : url.getPort();
65+
boolean isHttps = "https".equalsIgnoreCase(url.getProtocol());
66+
this.remoteApiSsl = isHttps;
67+
this.remoteApiPort = -1 == url.getPort() ? (isHttps ? 443 : 80) : url.getPort();
6568
this.remoteApiHost = url.getHost();
6669
this.remoteApiPath = url.getPath();
6770
this.remoteApiBearerToken = "Bearer " + operatorKey;
@@ -70,6 +73,7 @@ public CloudSyncOptOutStore(Vertx vertx, ICloudStorage fsLocal, JsonObject jsonC
7073
this.remoteApiHost = null;
7174
this.remoteApiPath = null;
7275
this.remoteApiBearerToken = null;
76+
this.remoteApiSsl = false;
7377
}
7478

7579
this.snapshot.set(new OptOutStoreSnapshot(fsLocal, jsonConfig, clock));
@@ -101,13 +105,17 @@ public void addEntry(UserIdentity firstLevelHashIdentity,
101105
return;
102106
}
103107

104-
HttpRequest<String> request = this.webClient.post(remoteApiPort, remoteApiHost, remoteApiPath).
105-
addQueryParam("identity_hash", EncodingUtils.toBase64String(firstLevelHashIdentity.id))
108+
HttpRequest<String> request = this.webClient.post(remoteApiPort, remoteApiHost, remoteApiPath)
109+
.addQueryParam("identity_hash", EncodingUtils.toBase64String(firstLevelHashIdentity.id))
106110
.addQueryParam("advertising_id", EncodingUtils.toBase64String(advertisingId))
107111
.putHeader("Authorization", remoteApiBearerToken)
108112
.putHeader(Audit.UID_INSTANCE_ID_HEADER, uidInstanceId)
109113
.as(BodyCodec.string());
110114

115+
if (remoteApiSsl) {
116+
request = request.ssl(true);
117+
}
118+
111119
JsonObject payload = new JsonObject();
112120
if (email != null) payload.put("email", email);
113121
if (phone != null) payload.put("phone", phone);

0 commit comments

Comments
 (0)