Serve Polymer 2 host page, if 'p2' URL parameter is set
Change-Id: I550610aeff1726450c1ed60ac9aeb8ea7aaffc5d
This commit is contained in:
@@ -49,10 +49,13 @@ public class IndexHtmlUtil {
|
||||
String canonicalURL,
|
||||
String cdnPath,
|
||||
String faviconPath,
|
||||
Map<String, String[]> urlParameterMap,
|
||||
Function<String, SanitizedContent> urlInScriptTagOrdainer)
|
||||
throws URISyntaxException, RestApiException {
|
||||
return ImmutableMap.<String, Object>builder()
|
||||
.putAll(staticTemplateData(canonicalURL, cdnPath, faviconPath, urlInScriptTagOrdainer))
|
||||
.putAll(
|
||||
staticTemplateData(
|
||||
canonicalURL, cdnPath, faviconPath, urlParameterMap, urlInScriptTagOrdainer))
|
||||
.putAll(dynamicTemplateData(gerritApi))
|
||||
.build();
|
||||
}
|
||||
@@ -94,6 +97,7 @@ public class IndexHtmlUtil {
|
||||
String canonicalURL,
|
||||
String cdnPath,
|
||||
String faviconPath,
|
||||
Map<String, String[]> urlParameterMap,
|
||||
Function<String, SanitizedContent> urlInScriptTagOrdainer)
|
||||
throws URISyntaxException {
|
||||
String canonicalPath = computeCanonicalPath(canonicalURL);
|
||||
@@ -116,6 +120,9 @@ public class IndexHtmlUtil {
|
||||
if (faviconPath != null) {
|
||||
data.put("faviconPath", faviconPath);
|
||||
}
|
||||
if (urlParameterMap.containsKey("p2")) {
|
||||
data.put("polymer2", "true");
|
||||
}
|
||||
return data.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.google.gerrit.httpd.raw;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.io.Resources;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.extensions.api.GerritApi;
|
||||
@@ -28,6 +29,7 @@ import com.google.template.soy.tofu.SoyTofu;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -67,14 +69,16 @@ public class IndexServlet extends HttpServlet {
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
|
||||
SoyTofu.Renderer renderer;
|
||||
try {
|
||||
Map<String, String[]> parameterMap = req.getParameterMap();
|
||||
// TODO(hiesel): Remove URL ordainer as parameter once Soy is consistent
|
||||
ImmutableMap<String, Object> templateData =
|
||||
IndexHtmlUtil.templateData(
|
||||
gerritApi, canonicalUrl, cdnPath, faviconPath, parameterMap, urlOrdainer);
|
||||
renderer =
|
||||
soyTofu
|
||||
.newRenderer("com.google.gerrit.httpd.raw.Index")
|
||||
.setContentKind(SanitizedContent.ContentKind.HTML)
|
||||
.setData(
|
||||
IndexHtmlUtil.templateData(
|
||||
gerritApi, canonicalUrl, cdnPath, faviconPath, urlOrdainer));
|
||||
.setData(templateData);
|
||||
} catch (URISyntaxException | RestApiException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
|
||||
@@ -17,21 +17,42 @@ package com.google.gerrit.httpd.raw;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.httpd.raw.IndexHtmlUtil.staticTemplateData;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.template.soy.data.SanitizedContent;
|
||||
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer;
|
||||
import java.util.HashMap;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IndexHtmlUtilTest {
|
||||
@Test
|
||||
public void polymer2() throws Exception {
|
||||
assertThat(
|
||||
staticTemplateData(
|
||||
"http://example.com/",
|
||||
null,
|
||||
null,
|
||||
ImmutableMap.of("p2", new String[0]),
|
||||
IndexHtmlUtilTest::ordain))
|
||||
.containsExactly("canonicalPath", "", "polymer2", "true", "staticResourcePath", ordain(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noPathAndNoCDN() throws Exception {
|
||||
assertThat(staticTemplateData("http://example.com/", null, null, IndexHtmlUtilTest::ordain))
|
||||
assertThat(
|
||||
staticTemplateData(
|
||||
"http://example.com/", null, null, new HashMap<>(), IndexHtmlUtilTest::ordain))
|
||||
.containsExactly("canonicalPath", "", "staticResourcePath", ordain(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathAndNoCDN() throws Exception {
|
||||
assertThat(
|
||||
staticTemplateData("http://example.com/gerrit/", null, null, IndexHtmlUtilTest::ordain))
|
||||
staticTemplateData(
|
||||
"http://example.com/gerrit/",
|
||||
null,
|
||||
null,
|
||||
new HashMap<>(),
|
||||
IndexHtmlUtilTest::ordain))
|
||||
.containsExactly("canonicalPath", "/gerrit", "staticResourcePath", ordain("/gerrit"));
|
||||
}
|
||||
|
||||
@@ -42,6 +63,7 @@ public class IndexHtmlUtilTest {
|
||||
"http://example.com/",
|
||||
"http://my-cdn.com/foo/bar/",
|
||||
null,
|
||||
new HashMap<>(),
|
||||
IndexHtmlUtilTest::ordain))
|
||||
.containsExactly(
|
||||
"canonicalPath", "", "staticResourcePath", ordain("http://my-cdn.com/foo/bar/"));
|
||||
@@ -54,6 +76,7 @@ public class IndexHtmlUtilTest {
|
||||
"http://example.com/gerrit",
|
||||
"http://my-cdn.com/foo/bar/",
|
||||
null,
|
||||
new HashMap<>(),
|
||||
IndexHtmlUtilTest::ordain))
|
||||
.containsExactly(
|
||||
"canonicalPath", "/gerrit", "staticResourcePath", ordain("http://my-cdn.com/foo/bar/"));
|
||||
|
||||
Reference in New Issue
Block a user