Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-16838 Follow-up, new optional CLDR_REDIRECT_PORT in cldr.properties #3389

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.unicode.cldr.test.DisplayAndInputProcessor;
import org.unicode.cldr.util.CLDRConfig;
import org.unicode.cldr.util.CLDRLocale;
import org.unicode.cldr.util.Level;
import org.unicode.cldr.util.PathHeader;
Expand Down Expand Up @@ -719,14 +720,39 @@ void print(Throwable t) {
*/
void redirect(String where) {
try {
response.sendRedirect(where);
String port = getRedirectPort();
if (port != null) {
String url =
request.getScheme() + "://" + request.getServerName() + ":" + port + where;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do you know what the scheme is?

couldn't this all just pull from CLDR_SURVEY_URL in the settings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe -- I didn't try that; I figured, like the original code, use the scheme and server name from the existing request, and just fix the port since that's what was broken when using 8888 for nginx

response.sendRedirect(url);
} else {
response.sendRedirect(where);
}
out.close();
close();
} catch (IOException ioe) {
throw new RuntimeException(ioe + " while redirecting to " + where);
}
}

private static final String PORT_NUMBER_NOT_INITIALIZED = "?";

/**
* On first access, this becomes either null (for default port number 80) or a port number such
* as "8888". Ordinarily Survey Tool uses nginx as a load-balancing server, running on the
* default port (80). For development it may be useful to have it on a different port. This can
* be enabled by a line such as this in cldr.properties: CLDR_REDIRECT_PORT=8888
*/
private static String webContextRedirectPort = PORT_NUMBER_NOT_INITIALIZED;

private String getRedirectPort() {
if (PORT_NUMBER_NOT_INITIALIZED.equals(webContextRedirectPort)) {
webContextRedirectPort =
CLDRConfig.getInstance().getProperty("CLDR_REDIRECT_PORT", null);
}
return webContextRedirectPort; // default null
}

/** Close the stream. Normally not called directly, except in outermost processor. */
void close() throws IOException {
if (!dontCloseMe) {
Expand Down
Loading