void FTPStreamFactoryTest::testMissingPasswordProvider()
{
	FTPStreamFactory::setPasswordProvider(0);

	DialogServer server;
	server.addResponse("220 localhost FTP ready");
	server.addResponse("221 Good bye");

	URI uri;
	uri.setScheme("ftp");
	uri.setHost("localhost");
	uri.setPort(server.port());
	uri.setPath("/test.txt;type=a");
	uri.setUserInfo("user");

	try
	{
		FTPStreamFactory sf;
		std::auto_ptr<std::istream> pStr(sf.open(uri));
		fail("no password provider - must throw");
	}
	catch (FTPException&)
	{
	}
}
void FTPStreamFactoryTest::testDownload()
{
	FTPStreamFactory::setPasswordProvider(0);

	DialogServer server;
	server.addResponse("220 localhost FTP ready");
	server.addResponse("331 Password required");
	server.addResponse("230 Welcome");
	server.addResponse("200 Type set to I");
	server.addResponse("200 Type set to A");

	DialogServer dataServer(false);
	dataServer.addResponse("line1\r\nline2");
	std::ostringstream epsv;
	epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
	server.addResponse(epsv.str());
	server.addResponse("150 sending data\r\n226 Transfer complete");
	server.addResponse("221 Good bye");

	URI uri;
	uri.setScheme("ftp");
	uri.setHost("localhost");
	uri.setPort(server.port());
	uri.setPath("/test.txt;type=a");
	FTPStreamFactory sf;
	std::auto_ptr<std::istream> pStr(sf.open(uri));

	std::ostringstream dataStr;
	StreamCopier::copyStream(*pStr.get(), dataStr);
	
	pStr.reset();
		
	std::string s(dataStr.str());
	assert (s == "line1\r\nline2\r\n");
}
示例#3
0
URI Transaction::resolve(const URI &_uri) {
  URI uri = _uri;

  if (uri.getHost().empty()) {
    uri.setHost(address.getHost());
    if (uri.getScheme().empty()) uri.setScheme("http");
    if (!uri.getPort()) uri.setPort(address.getPort());
  }

  return uri;
}
bool RedirectSecure::operator()(Request &req) {
  if (req.isSecure()) return false; // Pass it on

  // Set scheme, host & port
  URI uri = req.getURI();
  uri.setScheme("https");
  uri.setHost(IPAddress(req.getHost()).getHost());
  uri.setPort(port == 443 ? 0 : port);

  // Redirect
  req.redirect(uri);

  return true;
}