More work on SSL support.
You can now accept SSL connections using SSLListeners, and then send/receive data through the associated SSLSocket. HttpSocket's now support both HTTP and HTTPS, using templates: fr::HttpSocket<fr::SSLSocket> https_socket; fr::HttpSocket<fr::TcpSocket> http_socket;
This commit is contained in:
+24
-3
@@ -10,7 +10,8 @@
|
||||
|
||||
namespace fr
|
||||
{
|
||||
class HttpSocket : public TcpSocket
|
||||
template<class SocketType>
|
||||
class HttpSocket : public SocketType
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
@@ -19,7 +20,23 @@ namespace fr
|
||||
* @param request Where to store the received request.
|
||||
* @return The status of the operation.
|
||||
*/
|
||||
Socket::Status receive(Http &request);
|
||||
Socket::Status receive(Http &request)
|
||||
{
|
||||
//Create buffer to receive_request the request
|
||||
std::string buffer(2048, '\0');
|
||||
|
||||
//Receive the request
|
||||
size_t received;
|
||||
Socket::Status status = SocketType::receive_raw(&buffer[0], buffer.size(), received);
|
||||
if(status != Socket::Success)
|
||||
return status;
|
||||
buffer.resize(received);
|
||||
|
||||
//Parse it
|
||||
request.parse(buffer);
|
||||
|
||||
return Socket::Success;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Sends a HTTP request to the connected socket.
|
||||
@@ -27,7 +44,11 @@ namespace fr
|
||||
* @param request The HTTP request to send.
|
||||
* @return The status of the operation.
|
||||
*/
|
||||
Socket::Status send(const Http &request);
|
||||
Socket::Status send(const Http &request)
|
||||
{
|
||||
std::string data = request.construct(SocketType::remote_address);
|
||||
return SocketType::send_raw(&data[0], data.size());
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user