HTTPS¶
Description¶
IHttpCore uses asio for network support, and asio has built-in SSL support for the TCP protocol. SSL has already been supported in IHttpCore.
In the current version, to start the HTTPS protocol, users need to perform the following steps when starting the httpserver:
How to Do It¶
Integrate OpenSSL into the Program¶
To use HTTPS, users need to install the OpenSSL library and import it into their project. Since the OpenSSL library is large and compiled versions are available online, IHttpCore does not provide it. Users need to install it themselves and import it into their project.
The following is the configuration I used during testing, based on qmake, written in the pro file. Users can use this as a reference; it is not provided uniformly.
Enable the ENABLE_SSL Macro¶
Note the first line in the code above: DEFINES += ENABLE_SSL. Users must enable this macro to use HTTPS. The purpose of the ENABLE_SSL macro is to activate SSL functionality.
Modify the HTTP Server¶
Modify the usage of IHttpServer as follows:
The above code is what I used in my project; users can refer to it.
Note line 11: server.setSslContext(sslContext);. Users must set the initialized sslContext object into the server; otherwise, the server cannot provide SSL services properly.
Summary¶
Thus, the HTTPS server has been successfully started.