How to conveniently parse URIs in Casablanca

How to gracefully analyze the URI of a request (server side) in C ++?

A URI is defined as Casablanca Documentation as:

protocol: // server [: port] / path? REQUEST # fragment

Let's say that I want the path (with all the elements) to be a list and queries in the form of a list of key / value pairs, therefore

http: // server / foo / bar? val1 = 1 & val2 = yo

will result in

std::list<string> path;
path.push_back("foo");
path.push_back("bar");

std::list<std::pair<string, string>> query;
query.push_back(std::make_pair("val1", "1"));
query.push_back(std::make_pair("val2", "yo"));

I want to avoid parsing myself as suggested elsewhere , mainly for reasons of mobility and performance.

cpp-netlib doesn't seem to be part of the upgrade, and I prefer not to introduce a new library.

Casablanca URI, .

, boost, ++, casablanca/cpprestsdk?

+4
1

, URI- , . uri:: split_query uri:: split_path, .

,

auto http_get_vars = uri::split_query(request.request_uri().query());
+7

Source: https://habr.com/ru/post/1616552/


All Articles