[英]What is the role of a "Extension" in actix-web?
Extensions are used for storing request-local data.扩展用于存储请求本地数据。 They are different than application data since it is specific to individual requests.
它们与应用程序数据不同,因为它特定于单个请求。 And is different from headers since they are set within the server, not by the client.
并且与标头不同,因为它们是在服务器中设置的,而不是由客户端设置的。
This is primarily used for passing data between middleware and the handlers;这主要用于在中间件和处理程序之间传递数据; like authentication or route-prefix processing.
如身份验证或路由前缀处理。 They can be set in the middleware by
req.extensions_mut().insert(...)
and can be retrieved in the handler via req.extensions().get<...>()
or via the ReqData
extractor.它们可以通过
req.extensions_mut().insert(...)
在中间件中设置,并且可以通过req.extensions().get<...>()
或通过ReqData
提取器在处理程序中检索。
See also:也可以看看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.