Skip to content
Snippets Groups Projects
Commit f7cb62a9 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Merge branch 'f-x-forwarded-proto' into 'dev'

f-x-forwarded-proto -> dev

See merge request caosdb/caosdb-server!76
parents a08c8be2 d4c448fd
No related branches found
No related tags found
No related merge requests found
......@@ -117,7 +117,7 @@ public abstract class AbstractCaosDBServerResource extends ServerResource {
getRequest().setEntity(r);
}
this.utils = WebinterfaceUtils.getInstance(getHostRef());
this.utils = WebinterfaceUtils.getInstance(getRequest());
this.timestamp = getRequest().getDate().getTime();
......@@ -177,7 +177,7 @@ public abstract class AbstractCaosDBServerResource extends ServerResource {
retRoot.setAttribute("crid", this.getCRID());
}
retRoot.setAttribute("timestamp", getTimestamp().toString());
retRoot.setAttribute("baseuri", getRootRef().toString());
retRoot.setAttribute("baseuri", getUtils().getServerRootURI());
return retRoot;
}
......
......@@ -47,7 +47,7 @@ public class Webinterface extends ServerResource {
@Override
protected void doInit() throws ResourceException {
this.utils = WebinterfaceUtils.getInstance(getHostRef());
this.utils = WebinterfaceUtils.getInstance(getRequest());
super.doInit();
}
......
......@@ -39,7 +39,7 @@ public class WebinterfaceBuildNumber extends ServerResource {
@Override
protected void doInit() throws ResourceException {
super.doInit();
this.utils = WebinterfaceUtils.getInstance(getHostRef());
this.utils = WebinterfaceUtils.getInstance(getRequest());
}
/**
......
......@@ -33,6 +33,7 @@ import org.caosdb.server.CaosDBServer;
import org.caosdb.server.ServerProperties;
import org.caosdb.server.resource.AbstractCaosDBServerResource;
import org.caosdb.server.resource.Webinterface;
import org.restlet.Request;
import org.restlet.data.Reference;
/**
......@@ -61,14 +62,19 @@ public class WebinterfaceUtils {
private static final Map<String, WebinterfaceUtils> instances = new HashMap<>();
/**
* Retrieve an instance of {@link WebinterfaceUtils} for the host. The instance can be shared with
* other callers.
* Retrieve an instance of {@link WebinterfaceUtils} for the request. The instance can be shared
* with other callers.
*
* @param host
* @param request
* @return a shared instance of {@link WebinterfaceUtils}.
*/
public static WebinterfaceUtils getInstance(Reference host) {
return getInstance(host.getHostIdentifier());
public static WebinterfaceUtils getInstance(Request request) {
String hostStr = request.getHostRef().getHostIdentifier();
String scheme = request.getHeaders().getFirstValue("X-Forwarded-Proto", true);
if (scheme != null) {
hostStr = hostStr.replaceFirst("^" + request.getHostRef().getScheme(), scheme);
}
return getInstance(hostStr);
}
/**
......
......@@ -26,6 +26,7 @@ import org.caosdb.server.database.backend.interfaces.RetrieveRoleImpl;
import org.caosdb.server.database.exceptions.TransactionException;
import org.caosdb.server.database.misc.TransactionBenchmark;
import org.caosdb.server.permissions.PermissionRule;
import org.caosdb.server.utils.WebinterfaceUtils;
import org.jdom2.Element;
import org.junit.BeforeClass;
import org.junit.Rule;
......@@ -125,6 +126,11 @@ public class TestAbstractCaosDBServerResource {
// TODO Auto-generated method stub
return user;
}
@Override
public WebinterfaceUtils getUtils() {
return WebinterfaceUtils.getInstance(getRootRef().toString());
}
};
provideUserSourcesFile();
Element response = s.generateRootElement();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment