| 298 | // ── GET ────────────────────────────────────────────────────────────────────── |
| 299 | |
| 300 | void WebDAVHandler::handleGet(WebServer& s) { |
| 301 | String path = getRequestPath(s); |
| 302 | LOG_DBG("DAV", "GET %s", path.c_str()); |
| 303 | |
| 304 | if (isProtectedPath(path)) { |
| 305 | s.send(403, "text/plain", "Forbidden"); |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | if (!Storage.exists(path.c_str())) { |
| 310 | s.send(404, "text/plain", "Not Found"); |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | HalFile file = Storage.open(path.c_str()); |
| 315 | if (!file) { |
| 316 | s.send(500, "text/plain", "Failed to open file"); |
| 317 | return; |
| 318 | } |
| 319 | if (file.isDirectory()) { |
| 320 | file.close(); |
| 321 | // For directories, return a PROPFIND-like response or redirect |
| 322 | s.send(405, "text/plain", "Method Not Allowed"); |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | String contentType = getMimeType(path); |
| 327 | s.setContentLength(file.size()); |
| 328 | s.send(200, contentType.c_str(), ""); |
| 329 | |
| 330 | NetworkClient client = s.client(); |
| 331 | client.write(file); |
| 332 | file.close(); |
| 333 | } |
| 334 | |
| 335 | // ── HEAD ───────────────────────────────────────────────────────────────────── |
| 336 | |