Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Https server with cpp-netlib

Tags:

How can one use cpp-netlib to implement a HTTPS-server?

  • cpp-netlib can be used as a HTTP server (see service selector, handler and main in my example code).
  • With boost::asio setting up a SSL connection is not too hard (see my attempt at SSL).
  • cpp-netlib accepts a boost::asio::io_service via the options provided to the constructor (cpp-netlib reference)

The following questions stop me from combining asio SSL and cpp-netlib:

  • Both SSL via asio and cpp-netlib use an asio acceptor that listens to a port (e.g. 80 or 443) and then a separate session for the actual connection.

    I assume that for HTTPS:

    1. You use the asio ssl acceptor
    2. Which instantiates a connection
    3. Then perform the SSL handshake over this connection, and finally
    4. Have cpp-netlib serve HTTP over this connection

    But how can I separate cpp-netlib's HTTP connection handler from the acceptor is uses?

  • Or does one pass a io_service from the asio SSL connection? If so, which one? Or are they all the same?

  • Or is there a completely different route to take?

like image 479
Kasper van den Berg Avatar asked Dec 11 '13 17:12

Kasper van den Berg


2 Answers

A long shot, but have you tried the following:

  • #define BOOST_NETWORK_ENABLE_HTTPS
    before including the boost network http client.

  • Make sure OpenSSL is in the compiler path.

like image 95
bosnjak Avatar answered Mar 04 '23 21:03

bosnjak


The most recent release of cpp-netlib contains a working example. You'll find it in cpp-netlib-0.11.1RC2/libs/network/example/http/ssl. The github files are there: https://github.com/cpp-netlib/cpp-netlib/tree/0.11-devel/libs/network/example/http/ssl

You have to use an async_server.

like image 30
Rémi Avatar answered Mar 04 '23 22:03

Rémi