RESTinio v0.6.8 Release Notes

Release Date: 2020-05-15 // almost 4 years ago
  • ๐Ÿ›  Implementation of extraction of Bearer authentification parameters fixed. Now it looks like:

    #include \<restinio/all.hpp\>#include \<restinio/http\_field\_parser/bearer\_auth.hpp\>...auto on\_request(const restinio::request\_handle\_t & req) { using namespace restinio::http\_field\_parsers::bearer\_auth;const auto auth\_params = try\_extract\_params(\*req, restinio::http\_field::authorization); if(auth\_params) { // Parameters successfully extracted.if(is\_valid\_user(auth\_params-\>token)) { ... } } ... }
    

    ๐Ÿ“œ New helper function try_parse_field for simplification of HTTP-fields parsing added:

    #include \<restinio/all.hpp\>#include \<restinio/helpers/http\_fields\_parsers/try\_parse\_field.hpp\>#include \<restinio/helpers/http\_fields\_parsers/accept.hpp\>...auto on\_request(const restinio::request\_handle\_t & req) { using namespace restinio::http\_field\_parsers;// Try to get and parse the value of `Accept` header.const auto parse\_result = try\_parse\_field\<accept\_value\_t\>( req, restinio::http\_field::accept); if(const auto \* value = restinio::get\_if\<accept\_value\_t\>(&parse\_result)) { // Value of the field is successfully parsed. ... // Some usage of parsed value. } }
    

    Several new overloads for try_extract_params functions from restinio::http_field_parsers::basic_auth and restinio::http_field_parsers::bearer_auth namespaces. They allow to work with several authentication schemes after the parsing of Authorization (Proxy-Authorization) field:

    auto on\_request(const restinio::request\_handle\_t & req) { using namespace restinio::http\_field\_parsers;const auto field = try\_parse\_field\<authorization\_value\_t\>( req, restinio::http\_field::authorization); if(const auto \* auth = restinio::get\_if\<authorization\_value\_t\>(field)) { // We have valid Authorization field value.if("basic" == auth-\>auth\_scheme) { // Basic authentification scheme should be used.using namespace restinio::http\_field\_parsers::basic\_auth;const auto params = try\_extract\_params(auth-\>auth\_params); if(params) { // Parameters successfully extracted.if(is\_valid\_user(params-\>username, params-\>password)) { ... } } ... } else if("bearer" == auth-\>auth\_scheme) { // Bearer authentification scheme should be used.using namespace restinio::http\_field\_parsers::bearer\_auth;const auto params = try\_extract\_params(auth-\>auth\_params); if(auth\_params) { // Parameters successfully extracted.if(is\_valid\_user(auth\_params-\>token)) { ... } } ... } else { ... // Handling of different schemes. } } }