예제 #1
0
	void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
	{
		Application& app = Application::instance();
		app.logger().information("Request from " + request.clientAddress().toString());

		SecureStreamSocket socket = static_cast<HTTPServerRequestImpl&>(request).socket();
		if (socket.havePeerCertificate())
		{
			X509Certificate cert = socket.peerCertificate();
			app.logger().information("Client certificate: " + cert.subjectName());
		}
		else
		{
			app.logger().information("No client certificate available.");
		}
		
		Timestamp now;
		std::string dt(DateTimeFormatter::format(now, _format));

		response.setChunkedTransferEncoding(true);
		response.setContentType("text/html");

		std::ostream& ostr = response.send();
		ostr << "<html><head><title>HTTPTimeServer powered by POCO C++ Libraries</title>";
		ostr << "<meta http-equiv=\"refresh\" content=\"1\"></head>";
		ostr << "<body><p style=\"text-align: center; font-size: 48px;\">";
		ostr << dt;
		ostr << "</p></body></html>";
	}
예제 #2
0
void HTTPSClientSession::connect(const SocketAddress& address)
{
	if (getProxyHost().empty() || bypassProxy())
	{
		SecureStreamSocket sss(socket());
		if (sss.getPeerHostName().empty()) 
		{
			sss.setPeerHostName(getHost());
		}
		if (_pContext->sessionCacheEnabled())
		{
			sss.useSession(_pSession);
		}
		HTTPSession::connect(address);
		if (_pContext->sessionCacheEnabled())
		{
			_pSession = sss.currentSession();
		}
	}
	else
	{
		StreamSocket proxySocket(proxyConnect());
		SecureStreamSocket secureSocket = SecureStreamSocket::attach(proxySocket, getHost(), _pContext, _pSession);
		attachSocket(secureSocket);
		if (_pContext->sessionCacheEnabled())
		{
			_pSession = secureSocket.currentSession();
		}
	}
}
예제 #3
0
void HTTPSClientSessionTest::testConnectNB()
{
	SecureStreamSocket sock;
	sock.connectNB(SocketAddress("server.com", 443));
	char buf[512];
	std::string msg("GET / HTTP/1.0\r\n\r\n");
	sock.sendBytes(msg.c_str(), (int)msg.length());
	Socket::SocketList read;
	Socket::SocketList write;
	Socket::SocketList exec;
	read.push_back(sock);
	Socket::select(read, write, exec, Poco::Timespan(30, 0) );
	int rc = sock.receiveBytes(buf, 512);
	assert (rc > 0);
}
예제 #4
0
HTTPSClientSession::HTTPSClientSession(const SecureStreamSocket& socket, Session::Ptr pSession):
	HTTPClientSession(socket),
	_pContext(socket.context()),
	_pSession(pSession)
{
	setPort(HTTPS_PORT);
}
예제 #5
0
void HTTPSClientSession::connect(const SocketAddress& address)
{
	if (getProxyHost().empty())
	{
		SecureStreamSocket sss(socket());
		if (_pContext->sessionCacheEnabled())
		{
			sss.useSession(_pSession);
		}
		HTTPSession::connect(address);
		if (_pContext->sessionCacheEnabled())
		{
			_pSession = sss.currentSession();
		}
	}
	else
	{
		HTTPClientSession proxySession(address);
		proxySession.setHost(getProxyHost());
		proxySession.setPort(getProxyPort());
		proxySession.setTimeout(getTimeout());
		SocketAddress targetAddress(getHost(), getPort());
		HTTPRequest proxyRequest(HTTPRequest::HTTP_CONNECT, targetAddress.toString(), HTTPMessage::HTTP_1_1);
		HTTPResponse proxyResponse;
		proxyRequest.set("Proxy-Connection", "keep-alive");
		proxyRequest.set("Host", getHost());
		proxyAuthenticateImpl(proxyRequest);
		proxySession.setKeepAlive(true);
		proxySession.sendRequest(proxyRequest);
		proxySession.receiveResponse(proxyResponse);
		if (proxyResponse.getStatus() != HTTPResponse::HTTP_OK)
			throw HTTPException("Cannot establish proxy connection", proxyResponse.getReason());
		
		StreamSocket proxySocket(proxySession.detachSocket());
		SecureStreamSocket secureSocket = SecureStreamSocket::attach(proxySocket, getHost(), _pContext, _pSession);
		attachSocket(secureSocket);
		if (_pContext->sessionCacheEnabled())
		{
			_pSession = secureSocket.currentSession();
		}
	}
}
HTTPSClientSession::HTTPSClientSession(const SecureStreamSocket& rSocket):
	HTTPClientSession(rSocket),
	_pContext(rSocket.context())
{
	setPort(HTTPS_PORT);
}