如果客户端请求 proto://hostname:port/path
我想得到 proto://hostname:port
.
我可能错过了一些东西,但现在我能想到的唯一方法就是使用类似的东西
(format nil "~A://~A" (stringify-downcase-scan (server-protocol*)) (host))
是否有任何特定的功能/方法或更简单的方法?
主要原因是
server-protocol
返回一个我必须解析的关键字符号(例如 :http/1.1
)。我当然可以做到,但它可能已经存在,而我可能已经错过了。
最佳答案
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/