Skip to content
Snippets Groups Projects
Commit ccde825e authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

Merge branch 'f-filesystem-response-url' into 'dev'

F filesystem response url

See merge request !100
parents 1840d03d d25e9d75
No related branches found
No related tags found
2 merge requests!103Release 0.11.0,!100F filesystem response url
Pipeline #40093 failed
......@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`GRPC_RESPONSE_LOG_FORMAT` which control the format and information included
in the log message of any response of the respective API. See
`conf/core/server.conf` for more information.
* REST API: Permanent redirect from "FileSystem" to "FileSystem/".
### Changed ###
......@@ -22,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ###
* Wrong url returned by FileSystem resource behind proxy.
* `NullPointerException` in GRPC API converters when executing SELECT query on
NULL values.
......
......@@ -108,6 +108,7 @@ import org.restlet.data.Reference;
import org.restlet.data.ServerInfo;
import org.restlet.data.Status;
import org.restlet.engine.Engine;
import org.restlet.routing.Redirector;
import org.restlet.routing.Route;
import org.restlet.routing.Router;
import org.restlet.routing.Template;
......@@ -708,6 +709,9 @@ public class CaosDBServer extends Application {
protectedRouter.attach("/EntityPermissions/", EntityPermissionsResource.class);
protectedRouter.attach("/EntityPermissions/{specifier}", EntityPermissionsResource.class);
protectedRouter.attach("/Owner/{specifier}", EntityOwnerResource.class);
protectedRouter.attach(
"/FileSystem",
new Redirector(getContext(), "/FileSystem/", Redirector.MODE_CLIENT_PERMANENT));
protectedRouter.attach("/FileSystem/", FileSystemResource.class);
// FileSystem etc. needs to accept parameters which contain slashes and would otherwise be
// split at the first separator
......
......@@ -86,14 +86,16 @@ public class FileSystemResource extends AbstractCaosDBServerResource {
}
if (file.isDirectory()) {
String referenceString = getReference().toString();
if (!referenceString.endsWith("/")) {
referenceString = referenceString + "/";
}
String path = (specifier.endsWith("/") ? specifier : specifier + "/");
String url =
getUtils().getServerRootURI()
+ "/FileSystem"
+ (path.startsWith("/") ? path : ("/" + path));
final Element folder = new Element("dir");
folder.setAttribute("path", (specifier.endsWith("/") ? specifier : specifier + "/"));
folder.setAttribute("path", path);
folder.setAttribute("name", file.getName());
folder.setAttribute("url", referenceString);
folder.setAttribute("url", url);
final boolean thumbnailsExist =
new File(file.getAbsolutePath() + File.separator + ".thumbnails").exists();
......@@ -110,7 +112,7 @@ public class FileSystemResource extends AbstractCaosDBServerResource {
}
if (thumbnailsExist) {
final Attribute thumbnailAttribute = getThumbnailAttribute(file, child, referenceString);
final Attribute thumbnailAttribute = getThumbnailAttribute(file, child, url);
if (thumbnailAttribute != null) {
celem.setAttribute(thumbnailAttribute);
}
......
......@@ -61,6 +61,23 @@ public class WebinterfaceUtils {
private long buildNumberDate;
private static final Map<String, WebinterfaceUtils> instances = new HashMap<>();
public static String getForwardedProto(Request request) {
String scheme = null;
String forwarded = request.getHeaders().getFirstValue("Forwarded", true);
if (forwarded != null) {
for (String directive : forwarded.split(";")) {
String[] s = directive.split("=", 2);
if (s.length == 2 && "proto".equalsIgnoreCase(s[0])) {
scheme = s[1];
}
}
}
if (scheme == null) {
scheme = request.getHeaders().getFirstValue("X-Forwarded-Proto", true);
}
return scheme;
}
/**
* Retrieve an instance of {@link WebinterfaceUtils} for the request. The instance can be shared
* with other callers.
......@@ -70,7 +87,7 @@ public class WebinterfaceUtils {
*/
public static WebinterfaceUtils getInstance(Request request) {
String hostStr = request.getHostRef().getHostIdentifier();
String scheme = request.getHeaders().getFirstValue("X-Forwarded-Proto", true);
String scheme = getForwardedProto(request);
if (scheme != null) {
hostStr = hostStr.replaceFirst("^" + request.getHostRef().getScheme(), scheme);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment