Skip to content

Commit 213753f

Browse files
authored
TNT-40894 Fix incorrect MaxAge set in response cookies (#15)
+ minor VisitorProvider fix
1 parent da050ec commit 213753f

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

Source/Adobe.Target.Client/Util/CookieUtils.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ internal static Dictionary<string, string> ParseTargetCookie(string? targetCooki
6464
return nodeDetails.Length != 2 ? null : nodeDetails[0];
6565
}
6666

67-
internal static TargetCookie? CreateTargetCookie(string sessionId, string deviceId)
67+
internal static TargetCookie? CreateTargetCookie(string? sessionId, string? deviceId)
6868
{
6969
var nowInSeconds = GetNowInSeconds();
7070
var targetCookieValue = new StringBuilder();
71-
long maxAge = 0;
71+
var maxAge = 0;
7272
maxAge = CreateSessionId(sessionId, nowInSeconds, targetCookieValue, maxAge);
7373
maxAge = CreateDeviceId(deviceId, nowInSeconds, targetCookieValue, maxAge);
7474
var cookieValue = targetCookieValue.ToString();
7575

76-
return string.IsNullOrEmpty(cookieValue) ? null : new TargetCookie(TargetConstants.MboxCookieName, cookieValue, (int)(maxAge / 1000));
76+
return string.IsNullOrEmpty(cookieValue) ? null : new TargetCookie(TargetConstants.MboxCookieName, cookieValue, maxAge);
7777
}
7878

79-
internal static TargetCookie? CreateClusterCookie(string tntId)
79+
internal static TargetCookie? CreateClusterCookie(string? tntId)
8080
{
8181
if (tntId == null)
8282
{
@@ -90,45 +90,45 @@ internal static Dictionary<string, string> ParseTargetCookie(string? targetCooki
9090
return null;
9191
}
9292

93-
long maxAge = GetNowInSeconds() + ClusterLocationHintMaxAge;
93+
var maxAge = GetNowInSeconds() + ClusterLocationHintMaxAge;
9494

95-
return new TargetCookie(TargetConstants.ClusterCookieName, locationHint, (int)(maxAge / 1000));
95+
return new TargetCookie(TargetConstants.ClusterCookieName, locationHint, maxAge);
9696
}
9797

9898
private static int GetNowInSeconds()
9999
{
100100
return (int)(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() / 1000);
101101
}
102102

103-
private static long CreateDeviceId(string deviceId, int nowInSeconds, StringBuilder targetCookieValue, long maxAge)
103+
private static int CreateDeviceId(string? deviceId, int nowInSeconds, StringBuilder targetCookieValue, int maxAge)
104104
{
105105
if (string.IsNullOrEmpty(deviceId))
106106
{
107107
return maxAge;
108108
}
109109

110-
long deviceIdMaxAge = nowInSeconds + DeviceIdCookieMaxAge;
110+
var deviceIdMaxAge = nowInSeconds + DeviceIdCookieMaxAge;
111111
maxAge = Math.Max(maxAge, deviceIdMaxAge);
112112
AppendCookieValue(deviceId, targetCookieValue, deviceIdMaxAge, TargetConstants.DeviceIdCookieName);
113113

114114
return maxAge;
115115
}
116116

117-
private static long CreateSessionId(string sessionId, int nowInSeconds, StringBuilder targetCookieValue, long maxAge)
117+
private static int CreateSessionId(string? sessionId, int nowInSeconds, StringBuilder targetCookieValue, int maxAge)
118118
{
119119
if (string.IsNullOrEmpty(sessionId))
120120
{
121121
return maxAge;
122122
}
123123

124-
long sessionIdMaxAge = nowInSeconds + SessionIdCookieMaxAge;
124+
var sessionIdMaxAge = nowInSeconds + SessionIdCookieMaxAge;
125125
maxAge = sessionIdMaxAge;
126126
AppendCookieValue(sessionId, targetCookieValue, sessionIdMaxAge, TargetConstants.SessionIdCookieName);
127127

128128
return maxAge;
129129
}
130130

131-
private static void AppendCookieValue(string id, StringBuilder targetCookieValue, long maxAge, string cookieName)
131+
private static void AppendCookieValue(string? id, StringBuilder targetCookieValue, int maxAge, string cookieName)
132132
{
133133
targetCookieValue.Append(cookieName)
134134
.Append(InternalCookieSerializationSeparator)

Source/Adobe.Target.Client/Util/TargetConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static class TargetConstants
1818
/// <summary>
1919
/// SDK Version
2020
/// </summary>
21-
public const string SdkVersion = "1.0.1";
21+
public const string SdkVersion = "1.0.2";
2222

2323
/// <summary>
2424
/// Mbox cookie name

Source/Adobe.Target.Client/Util/VisitorProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ namespace Adobe.Target.Client.Util
1515

1616
internal sealed class VisitorProvider
1717
{
18+
private const string AmcvPrefix = "AMCV_";
1819
private static VisitorProvider instance;
1920
private string orgId;
2021

2122
private VisitorProvider(string orgId)
2223
{
2324
this.orgId = orgId;
24-
this.VisitorCookieName = new Visitor(orgId).AmcvCookieName;
25+
this.VisitorCookieName = AmcvPrefix + orgId;
2526
}
2627

2728
internal static VisitorProvider Instance

0 commit comments

Comments
 (0)