Hi Glyn and Jeroen,
On Tue, Nov 10, 2009 at 8:49 PM, Glyn Matthews <gly...@gm...> wrote:
> Hello Jeroen,
>
> 2009/11/10 Jeroen Habraken <vex...@gm...>
>>
>> Hi,
>>
>> I've been looking at cpp-netlib and it's great to finally see a
>> library focussing on the network side, and HTTP in specific. I was
>> wondering though if any of the current URI parsing implementations can
>> be used to parse the query-string of a URI into a map ?
>>
>
> Yeah this should certainly be possible but at the moment we're still working
> on the implementation so as yet, no working URI code. If you're interested
> and you have any suggestions you can contribute to the discussions on the
> wiki:
>
> http://sourceforge.net/apps/trac/cpp-netlib/wiki/URIAPIRequirements
>
> I don't know yet, but I imagine something similar to:
>
> namespace bn = boost::network;
> bn::http::uri instance("http://example.com/?foo=bar&x=y")
> std::string scheme, host, path;
> std::map<std::string, std::string> query_params;
> instance >> bn::scheme(scheme)
> >> bn::host(host)
> >> bn::path(path)
> >> bn::query(query_params);
This part I think can be simplified into something like this
(untested/unimplemented yet):
scheme = scheme(instance); // adl takes care of it for us
host = host(instance);
path = path(instance);
query_params_map = query(instance); // returns a proxy object convertible to
query_params_string = query(instance); // either a map or a string
Although I like the directive-based API (consistent with the message
directive-based API) I think for a URI implementation that might be a
little too verbose. ;)
I can also imagine something like this:
tie(scheme, host, path, query_params) = parts(instance);
I personally think there's a lot of opportunity for this space to be
explored, and offering many different APIs (like those discussed above
proposed by Glyn and I) would definitely be nice. :)
> assert(scheme == "http");
> assert(host == "example.com");
> assert(path == "/");
> assert(query_params["foo"] == "bar");
> assert(query_params["x"] == "y");
>
Looks like the beginnings of a test to me. ;) Glyn/Jeroen would you
like to file this as a Trac feature request assigned to me?
Thanks in advance! :D
--
Dean Michael Berris
blog.cplusplus-soup.com | twitter.com/mikhailberis
linkedin.com/in/mikhailberis | facebook.com/dean.berris | deanberris.com
|