You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by GitBox <gi...@apache.org> on 2022/10/06 20:35:53 UTC

[GitHub] [trafficserver] ywkaras commented on a diff in pull request #9107: Adds support for serving statichit content out of a directory

ywkaras commented on code in PR #9107:
URL: https://github.com/apache/trafficserver/pull/9107#discussion_r989460859


##########
plugins/experimental/statichit/statichit.cc:
##########
@@ -62,21 +63,80 @@ static int StaticHitInterceptHook(TSCont contp, TSEvent event, void *edata);
 static int StaticHitTxnHook(TSCont contp, TSEvent event, void *edata);
 
 struct StaticHitConfig {
-  explicit StaticHitConfig(const std::string &filePath, const std::string &mimeType, bool disableExact)
-    : filePath(filePath), mimeType(mimeType), disableExact(disableExact)
+  explicit StaticHitConfig(const std::string &fileOrDir, const std::string &mimeType, bool exact) : mimeType(mimeType)
   {
+    std::filesystem::path base_path;
+
+    if (fileOrDir.find('/') != 0) {
+      base_path = std::filesystem::weakly_canonical(std::string(TSConfigDirGet()) + "/" + fileOrDir);
+    } else {
+      base_path = std::filesystem::weakly_canonical(fileOrDir);
+    }
+
+    if (std::filesystem::is_directory(base_path)) {
+      dirPath      = base_path;
+      filePath     = "";
+      disableExact = true;
+    } else if (std::filesystem::is_regular_file(base_path)) {
+      dirPath      = "";
+      filePath     = base_path;
+      disableExact = exact;
+    } else {
+      VERROR("Invalid file path: %s", filePath.c_str());
+      filePath = "";
+      dirPath  = "";
+    }
   }
 
   ~StaticHitConfig() { TSContDestroy(cont); }
 
+  std::string_view
+  makePath(TSHttpTxn txnp, std::string &output) const

Review Comment:
   Why not just have this return std::string and eliminate the output parameter?  C++98 is so five minutes ago.



-- 
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: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org