I'm trying to figure out how Extensions are created in the actix-web Rust library. I think I'm missing the concept of request extensions. What do request extensions do? How are they different from HTTP headers?
            Asked
            
        
        
            Active
            
        
            Viewed 1,229 times
        
    5
            
            
        
        Shepmaster
        
- 388,571
 - 95
 - 1,107
 - 1,366
 
        pandawithcat
        
- 571
 - 2
 - 13
 
1 Answers
10
            
            
        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.
See also:
        kmdreko
        
- 42,554
 - 6
 - 57
 - 106