1

I want to be able to get HTTP request header values that contain utf8 characters in a server built with cpp-netlib. I understand that there are two kind of wrapper classes for requests and responses depending on the used string type - request_header_narrow and request_header_wide, but while browsing the code to understand how this is actually decided i came down to:

template <class Tag>
    struct request_header
    : mpl::if_<
        is_default_string<Tag>,
        request_header_narrow,
        typename mpl::if_<
            is_default_wstring<Tag>,
            request_header_wide,
            unsupported_tag<Tag>
        >::type
    >
    {};

and

namespace boost { namespace network {

    template <class Tag, class Enable = void>
    struct is_default_string : mpl::false_ {};

    template <class Tag>
    struct is_default_string<Tag, typename enable_if<typename Tag::is_default_string>::type> : mpl::true_ {};

} // namespace network

} // namespace boost

and

namespace boost { namespace network {

    template <class Tag, class Enable = void>
    struct is_default_wstring : mpl::false_ {};

    template <class Tag>
    struct is_default_wstring<Tag, typename enable_if<typename Tag::is_default_wstring>::type> : mpl::true_ {};

} // namespace network

} // namespace boost

Since i'm not too experienced with the template meta programming stuff i did not quite understand the Boosts mpl::if_ logic and how is the default string type actually determined if both have mpl::false_ as a default value? Can anyone either clear this or explain how to make cpp-netlib use std::wstring as default string type?

1 Answer 1

0

Seems I found at least one solution, not sure if it's the best so comments are welcome, but seems that at least one way to do this is define a new server tag set an then pass these tags to the server base class:

namespace boost { namespace network { namespace http { namespace tags {

    typedef mpl::vector<http, simple, async, pod, default_wstring, server> http_async_wstring_server_tags;

    BOOST_NETWORK_DEFINE_TAG(http_async_wstring_server);

} /* tags */

} /* http */

} /* network */

} /* boost */

namespace http = boost::network::http;
...
typedef http::server_base<http::tags::http_async_wstring_server, CHTTPRequestHandler>::type async_server;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.