0

I'm successfully using cpp-netlib (v0.11.0) and I'm developing some unit tests to test my HTTP server and handler function.

The handler function has the following required signature:

typedef boost::network::http::server<RequestHandler> HttpServerType; 

void operator()(const HttpServerType::request& request, HttpServerType::response& response)

What I'd like to be able to do is instantiate the request object so I can call the handler's function call operator. But I can't get it to compile.

In the above signature, request is a typedef for basic_request<Tag>,

which has a constructor which takes a reference to a boost::network::uri::uri.

The code below generates an error when compiled using clang 3.5.

boost::network::uri::uri url;

url << uri::scheme("http") << uri::host(host) << uri::port(port) << uri::path(path);

HttpServerType::request request(url);


No matching constructor for initialization of 'HttpServerType::request' (aka 'basic_request<boost::network::http::tags::http_server>');

What am I doing wrong?

ksl
  • 4,519
  • 11
  • 65
  • 106

1 Answers1

0

I found a way to do it.

The template is specialised for the http_server tag.

template <>
struct basic_request<tags::http_async_server> :
not_quite_pod_request_base<tags::http_async_server> 
{};

and this only has a default ctor.

The following code does compile:

HttpServerType::request request;
request.destination.append("fred"); 
request.method.append("POST");
ksl
  • 4,519
  • 11
  • 65
  • 106