commit 50af281a189d13ce6e0d8bd8c06798ec2181338e from: Alisdair MacLeod via: Alisdair MacLeod <131350026+admacleod@users.noreply.github.com> date: Wed Mar 25 16:33:41 2026 UTC Refactor routing to branch on path first, then method The flat if/else chain checked (method, path) pairs and required a separate block that re-enumerated every known path for the 405 case. Restructure as nested branches: outer level matches path, inner level matches method with a per-path else → 405 fallback. This makes each route self-contained so new paths cannot accidentally miss the 405 case. Co-Authored-By: Claude Opus 4.6 (1M context) commit - d3b734c59c04287dfb0438550d99c8f1b69c06c0 commit + 50af281a189d13ce6e0d8bd8c06798ec2181338e blob - 0fd26948843cb053bbc795858509a09691054327 blob + 57b02ef03332df05db7112fcd4a0e33fc440e9ea --- deskd.c +++ deskd.c @@ -142,26 +142,30 @@ main(int argc, char *argv[]) pathlen = strlen(path); /* Route the request. */ - if (strcmp(method, "GET") == 0 && strcmp(path, "/about") == 0) { - handle_about(); - } else if (strcmp(method, "GET") == 0 && strcmp(path, "/") == 0) { - handle_bookings(); - } else if (strcmp(method, "POST") == 0 && strcmp(path, "/") == 0) { - handle_cancel(); - } else if (strcmp(method, "GET") == 0 && - strcmp(path, "/book") == 0) { - handle_dateform(); - } else if (strcmp(method, "GET") == 0 && pathlen > 6 && - strncmp(path, "/book/", 6) == 0) { - handle_bookingform(path + 6); - } else if (strcmp(method, "POST") == 0 && pathlen > 6 && - strncmp(path, "/book/", 6) == 0) { - handle_book(path + 6); - } else if (strcmp(path, "/") == 0 || - strcmp(path, "/about") == 0 || - strcmp(path, "/book") == 0 || - (pathlen > 6 && strncmp(path, "/book/", 6) == 0)) { - cgi_error(405); + if (strcmp(path, "/") == 0) { + if (strcmp(method, "GET") == 0) + handle_bookings(); + else if (strcmp(method, "POST") == 0) + handle_cancel(); + else + cgi_error(405); + } else if (strcmp(path, "/about") == 0) { + if (strcmp(method, "GET") == 0) + handle_about(); + else + cgi_error(405); + } else if (strcmp(path, "/book") == 0) { + if (strcmp(method, "GET") == 0) + handle_dateform(); + else + cgi_error(405); + } else if (pathlen > 6 && strncmp(path, "/book/", 6) == 0) { + if (strcmp(method, "GET") == 0) + handle_bookingform(path + 6); + else if (strcmp(method, "POST") == 0) + handle_book(path + 6); + else + cgi_error(405); } else { cgi_error(404); }