request-utils.scm 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. (library (request-utils)
  2. (export request-path-components)
  3. (import
  4. (rnrs base)
  5. (only (guile) lambda* λ)
  6. ;; Guile exception handling
  7. (ice-9 exceptions)
  8. (ice-9 session)
  9. ;; web server, concurrent
  10. (fibers web server)
  11. ;; standard web library
  12. (web request)
  13. (web response)
  14. (web uri)
  15. (sxml simple)
  16. ;; custom modules
  17. (prefix (logging) log:)))
  18. (define request-path-components
  19. (λ (request)
  20. "Split a given request path up into its components. A
  21. request path is the route after the domain and host
  22. part. For example for
  23. http://localhost:8080/part1/part2/?blub=123 the result will
  24. be the list of containing the string part1 and the string
  25. part2."
  26. ;; split the string that represents the uri and decode
  27. ;; any url-endoced things
  28. ;; /part1/part2/ --> '("part1" "part2")
  29. (split-and-decode-uri-path
  30. ;; get the uri path as a string from the request struct
  31. ;; http://localhost:8080/part1/part2/?blub=123 --> /part1/part2/
  32. (uri-path
  33. ;; get the request-uri struct:
  34. ;; http://localhost:8080/abc/def/?abc=123 -->
  35. ;; #<<uri> scheme: #f userinfo: #f host: #f port: #f path: "/abc/def/"
  36. ;; query: "abc=123" fragment: #f>
  37. (request-uri request)))))