added HTTPS support
This commit is contained in:
parent
8c413fbd23
commit
401b9bbc69
4 changed files with 214 additions and 25 deletions
52
server_https.hpp
Normal file
52
server_https.hpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* File: httpsserver.hpp
|
||||
* Author: eidheim
|
||||
*
|
||||
* Created on July 12, 2014, 7:18 PM
|
||||
*/
|
||||
|
||||
#ifndef HTTPSSERVER_HPP
|
||||
#define HTTPSSERVER_HPP
|
||||
|
||||
#include "server_http.hpp"
|
||||
#include <boost/asio/ssl.hpp>
|
||||
|
||||
namespace SimpleWeb {
|
||||
typedef ssl::stream<ip::tcp::socket> HTTPS;
|
||||
|
||||
template<>
|
||||
class Server<HTTPS> : public ServerBase<HTTPS> {
|
||||
public:
|
||||
Server(unsigned short port, size_t num_threads, const string& cert_file, const string& private_key_file) :
|
||||
ServerBase<HTTPS>::ServerBase(port, num_threads), context(ssl::context::sslv23) {
|
||||
context.use_certificate_chain_file(cert_file);
|
||||
context.use_private_key_file(private_key_file, ssl::context::pem);
|
||||
}
|
||||
|
||||
private:
|
||||
ssl::context context;
|
||||
|
||||
void accept() {
|
||||
//Create new socket for this connection
|
||||
//Shared_ptr is used to pass temporary objects to the asynchronous functions
|
||||
shared_ptr<HTTPS> socket(new HTTPS(m_io_service, context));
|
||||
|
||||
acceptor.async_accept((*socket).lowest_layer(), [this, socket](const boost::system::error_code& ec) {
|
||||
//Immediately start accepting a new connection
|
||||
accept();
|
||||
|
||||
if(!ec) {
|
||||
(*socket).async_handshake(ssl::stream_base::server, [this, socket](const boost::system::error_code& ec) {
|
||||
if(!ec) {
|
||||
process_request_and_respond(socket);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif /* HTTPSSERVER_HPP */
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue