Catapult是一个 Igropyr 官方开发的 应用于 Igropyr 服务器的web开发框架。
install: raven install catapult
use: (import (catapult catapult))
req
procedure: (req (request_path handler) ...)
return: list
req接受任意数量的s表达式。
request_path 必须是字符串,而handler必须是一个过程。
返回的链表结构如下:
((request_path . handler)
...)
res
procedure: (res content)
procedure: (res status content)
procedure: (res type content)
procedure: (res status type content)
procedure: (res status type cookie content)
return: string
res 可以接受一至四个参数,并返回一个包含标准http头的字符串以便 Igropyr 的 request 回调将信息发送给客户端。
当res接受两个参数并且第一个参数是整形时,第一个参数被标记为状态码。
当res接受两个参数并且第一个参数是字符串时,第一个参数被标记为返回类型。
当res接受三个参数时,前两个参数被依次标记为状态码,返回类型。第一个参数必须为整形。
以上三种情况,和res只接受一个参数的时候,content都可以是一个list或者字符串。
当content是一个list时,它的第一个值被标记为cookie,第二个值被标记为返回内容。
当content是一个字符串时,它直接被标记为返回内容。而cookie被设为空。
当res接受四个参数时,参数被依次标记为状态码,返回类型,cookie,返回内容。第一个参数必须为整形,后三个参数必须为字符串。
未被标记的信息将使用默认值status: 200 type: text/html
通常用于取代 response 构建 request的 回调。
send
procedure: (send file_path)
procedure: (send type file_path)
return: string
send 可以接受一至二个参数。
当send只接受一个参数时,它被标记为文件路径。
当send接受两个参数时,第一个参数被标记为返回MIME类型,第二个被标记为文件路径。
当当文件类型未设定时,服务器会采用自动检测。
通常用于取代 sendfile 构建 request 的 回调。
router
procedure: (router route_list path)
return: procedure
router 接受一个路由信息链表和一个请求路径字符串,返回匹配路径的对应字符串或过程。
router 支持调用 Igropyr 提供的 par 过程进行模糊查找,查找首先遍历进行全匹配查询,
当全匹配查询的返回为空时进行包含*路径的模糊查询,请将包含*的路由写在后面以保证高效。
router 的查找是依次的,当取得值时就会退出并返回值,所以请将"/*"放到路由表的最后。
路由信息的链表结构为:
((request_path . handler)
...)
其中request_path必须是字符串,而handler必须是过程。
host?
procedure: (host? http-header)
return: string
用于在http-header中获取host值。
user-agent?
procedure: (user-agent? http-header)
return: string
用于在http-header中获取user-agent值。
accept-language?
procedure: (accept-language? http-header)
return: string
用于在http-header中获取accept-language值。
accept-encoding?
procedure: (accept-encoding? http-header)
return: string
用于在http-header中获取accept-encoding值。
cookie?
procedure: (cookie? http-header)
return: string
用于在http-header中获取cookie值。
connection?
procedure: (connection? http-header)
return: string
用于在http-header中获取connection值。
query-parser
procedure: (query-parser query key-value-spliter group-spliter)
return: association list
用于将 query 转换成 association list。