common-lisp - 在 hunchentoot 中有没有办法在路径之前获取 url 的一部分

标签 common-lisp hunchentoot

如果客户端请求 proto://hostname:port/path我想得到 proto://hostname:port .

我可能错过了一些东西,但现在我能想到的唯一方法就是使用类似的东西

(format nil "~A://~A" (stringify-downcase-scan (server-protocol*)) (host))

是否有任何特定的功能/方法或更简单的方法?

主要原因是server-protocol返回一个我必须解析的关键字符号(例如 :http/1.1 )。我当然可以做到,但它可能已经存在,而我可能已经错过了。

最佳答案

您可以安装 PURIQURI解析 URI:

CL-USER> (describe (quri:uri "proto://hostname:1000/path"))
#<QURI.URI:URI proto://hostname:1000/path>
Type: QURI.URI:URI
Class: #<STRUCTURE-CLASS QURI.URI:URI>
SCHEME: "proto"
USERINFO: NIL
HOST: "hostname"
PORT: 1000
PATH: "/path"
QUERY: NIL
FRAGMENT: NIL

然后,你可以这样做:
(quri:render-uri 
 (quri:merge-uris (quri:uri "/")
                  (quri:uri "proto://hostname:1000/path")))

=> "proto://hostname:1000/"

在您的情况下,您可能希望使用 (request-uri*) 访问 URI。 .

关于common-lisp - 在 hunchentoot 中有没有办法在路径之前获取 url 的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40693291/

相关文章:

lisp:捕获标准输出和标准错误,将其存储在单独的变量中

html - 当我使用 lisp 构建我的网站时出现了问题

common-lisp - 使用 RESTAS 和 Hunchentoot 进行用户身份验证

web - 什么是 restas 渲染对象?

common-lisp - Common Lisp共享结构困惑

common-lisp - Common Lisp中do循环中的多值绑定(bind)

common-lisp - 通用 Lisp : concatenate multiple values into vector

lisp - 如何在lisp中找到一个类的包?

routes - Hunchentoot(简单路线)路线出现在单独的项目中吗?

lisp - cl-who 和格式