Skip to content

Commit 2ef6dac

Browse files
Support akamai
1 parent e0dffc5 commit 2ef6dac

3 files changed

Lines changed: 31 additions & 14 deletions

File tree

src/com/cloudinary/Cloudinary.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020

2121
@SuppressWarnings({"rawtypes", "unchecked"})
2222
public class Cloudinary {
23-
public final static String SHARED_CDN = "d3jpl91pxevbkh.cloudfront.net";
24-
23+
public final static String CF_SHARED_CDN = "d3jpl91pxevbkh.cloudfront.net";
24+
public final static String AKAMAI_SHARED_CDN = "cloudinary-a.akamaihd.net";
25+
public final static String SHARED_CDN = AKAMAI_SHARED_CDN;
26+
2527
private final Map config = new HashMap();
2628

2729
public Cloudinary(Map config) {

src/com/cloudinary/Url.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,7 @@ public String generate(String source) {
111111
source = source + "." + format;
112112
}
113113
if (secure && StringUtils.isBlank(secureDistribution)) {
114-
if (privateCdn) {
115-
throw new IllegalArgumentException("secure_distribution not defined");
116-
} else {
117-
secureDistribution = Cloudinary.SHARED_CDN;
118-
}
114+
secureDistribution = Cloudinary.SHARED_CDN;
119115
}
120116
String prefix;
121117
if (secure) {
@@ -127,7 +123,7 @@ public String generate(String source) {
127123
String host = cname != null ? cname : (privateCdn ? cloudName + "-" : "") + "res.cloudinary.com";
128124
prefix = "http://" + subdomain + host;
129125
}
130-
if (!privateCdn) prefix = prefix + "/" + cloudName;
126+
if (!privateCdn || (secure && Cloudinary.AKAMAI_SHARED_CDN.equals(secureDistribution))) prefix = prefix + "/" + cloudName;
131127
if (version != null) version = "v" + version;
132128

133129
return StringUtils.join(new String[]{prefix, resourceType, type, transformationStr, version, source}, "/").replaceAll("([^:])\\/+", "$1/");

tests/com/cloudinary/test/CloudinaryTest.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void testCloudNameOptions() {
3636
public void testSecureDistribution() {
3737
// should use default secure distribution if secure=TRUE
3838
String result = cloudinary.url().secure(true).generate("test");
39-
assertEquals("https://d3jpl91pxevbkh.cloudfront.net/test123/image/upload/test", result);
39+
assertEquals("https://cloudinary-a.akamaihd.net/test123/image/upload/test", result);
4040
}
4141

4242
@Test
@@ -54,12 +54,31 @@ public void testSecureDistibution() {
5454
assertEquals("https://config.secure.distribution.com/test123/image/upload/test", result);
5555
}
5656

57-
@Test(expected = IllegalArgumentException.class)
58-
public void testMissingSecureDistribution() {
59-
// should raise exception if secure is given with private_cdn and no
60-
// secure_distribution
57+
@Test
58+
public void testSecureAkamai() {
59+
// should default to akamai if secure is given with private_cdn and no secure_distribution
60+
cloudinary.setConfig("secure", true);
61+
cloudinary.setConfig("private_cdn", true);
62+
String result = cloudinary.url().generate("test");
63+
assertEquals("https://cloudinary-a.akamaihd.net/test123/image/upload/test", result);
64+
}
65+
66+
@Test
67+
public void testSecureNonAkamai() {
68+
// should not add cloud_name if private_cdn and secure non akamai secure_distribution
69+
cloudinary.setConfig("secure", true);
6170
cloudinary.setConfig("private_cdn", true);
62-
cloudinary.url().secure(true).generate("test");
71+
cloudinary.setConfig("secure_distribution", "something.cloudfront.net");
72+
String result = cloudinary.url().generate("test");
73+
assertEquals("https://something.cloudfront.net/image/upload/test", result);
74+
}
75+
76+
@Test
77+
public void testHttpPrivateCdn() {
78+
// should not add cloud_name if private_cdn and not secure
79+
cloudinary.setConfig("private_cdn", true);
80+
String result = cloudinary.url().generate("test");
81+
assertEquals("http://test123-res.cloudinary.com/image/upload/test", result);
6382
}
6483

6584
@Test

0 commit comments

Comments
 (0)