You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@baremaps.apache.org by "github-code-scanning[bot] (via GitHub)" <gi...@apache.org> on 2023/06/16 22:08:36 UTC
[GitHub] [incubator-baremaps] github-code-scanning[bot] commented on a diff in pull request #705: Server refactoring
github-code-scanning[bot] commented on code in PR #705:
URL: https://github.com/apache/incubator-baremaps/pull/705#discussion_r1232834576
##########
baremaps-server/src/main/java/org/apache/baremaps/server/ClassPathResources.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.baremaps.server;
+
+import java.io.IOException;
+import java.io.InputStream;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import javax.ws.rs.GET;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Response;
+
+/**
+ * Serves static resources from the class path.
+ */
+@Singleton
+@javax.ws.rs.Path("/")
+public class ClassPathResources {
+
+ private final String directory;
+
+ private final String index;
+
+ /**
+ * Constructs a {@code ClassPathResources}.
+ *
+ * @param directory the directory
+ * @param index the index
+ */
+ @Inject
+ public ClassPathResources(
+ @Named("directory") String directory,
+ @Named("index") String index) {
+ this.directory = directory;
+ this.index = index;
+ }
+
+ /**
+ * Serves a static resource from the class path.
+ *
+ * @param path the path
+ * @return the response
+ */
+ @GET
+ @javax.ws.rs.Path("{path:.*}")
+ public Response get(@PathParam("path") String path) {
+ if (path.equals("") || path.endsWith("/")) {
Review Comment:
## Inefficient empty string test
Inefficient comparison to empty string, check for zero length instead.
[Show more details](https://github.com/apache/incubator-baremaps/security/code-scanning/675)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@baremaps.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org