| 86 | ~StaticHitConfig() { TSContDestroy(cont); } |
| 87 | |
| 88 | std::string_view |
| 89 | makePath(TSHttpTxn txnp, std::string &output) const |
| 90 | { |
| 91 | std::string_view ret = {}; |
| 92 | |
| 93 | if (!dirPath.empty()) { |
| 94 | TSMBuffer reqp; |
| 95 | TSMLoc hdr_loc = nullptr, url_loc = nullptr; |
| 96 | |
| 97 | if (TS_SUCCESS == TSHttpTxnClientReqGet(txnp, &reqp, &hdr_loc)) { |
| 98 | if (TS_SUCCESS == TSHttpHdrUrlGet(reqp, hdr_loc, &url_loc)) { |
| 99 | int path_len = 0; |
| 100 | auto path = TSUrlPathGet(reqp, url_loc, &path_len); |
| 101 | |
| 102 | std::filesystem::path requested_file_path( |
| 103 | std::filesystem::weakly_canonical(dirPath / std::string_view{path, static_cast<size_t>(path_len)})); |
| 104 | |
| 105 | TSHandleMLocRelease(reqp, hdr_loc, url_loc); |
| 106 | TSHandleMLocRelease(reqp, TS_NULL_MLOC, hdr_loc); |
| 107 | |
| 108 | if (std::equal(dirPath.begin(), dirPath.end(), requested_file_path.begin()) && |
| 109 | std::filesystem::is_regular_file(requested_file_path)) { |
| 110 | output = requested_file_path.string(); |
| 111 | ret = {output.c_str(), output.size()}; |
| 112 | } |
| 113 | } else { |
| 114 | TSHandleMLocRelease(reqp, TS_NULL_MLOC, hdr_loc); |
| 115 | } |
| 116 | } |
| 117 | } else { |
| 118 | ret = filePath; |
| 119 | } |
| 120 | |
| 121 | return ret; |
| 122 | } |
| 123 | |
| 124 | std::filesystem::path dirPath; |
| 125 | std::string filePath; |
no test coverage detected