changes from main repository

This commit is contained in:
Guenter Obiltschnig
2008-01-29 09:06:52 +00:00
parent ab8d8e38e3
commit b526dd81f2
47 changed files with 611 additions and 557 deletions

View File

@@ -1,7 +1,7 @@
//
// HTTPStreamFactory.cpp
//
// $Id: //poco/svn/Net/src/HTTPStreamFactory.cpp#2 $
// $Id: //poco/svn/Net/src/HTTPStreamFactory.cpp#3 $
//
// Library: Net
// Package: HTTP
@@ -78,14 +78,21 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
poco_assert (uri.getScheme() == "http");
URI resolvedURI(uri);
URI proxyUri;
HTTPClientSession* pSession = 0;
bool retry = false;
try
{
int redirects = 0;
do
{
pSession = new HTTPClientSession(resolvedURI.getHost(), resolvedURI.getPort());
pSession->setProxy(_proxyHost, _proxyPort);
if (proxyUri.empty())
pSession->setProxy(_proxyHost, _proxyPort);
else
pSession->setProxy(proxyUri.getHost(), proxyUri.getPort());
std::string path = resolvedURI.getPathAndQuery();
if (path.empty()) path = "/";
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
@@ -93,22 +100,35 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
HTTPResponse res;
std::istream& rs = pSession->receiveResponse(res);
bool moved = (res.getStatus() == HTTPResponse::HTTP_MOVED_PERMANENTLY ||
res.getStatus() == HTTPResponse::HTTP_FOUND ||
res.getStatus() == HTTPResponse::HTTP_SEE_OTHER);
res.getStatus() == HTTPResponse::HTTP_FOUND ||
res.getStatus() == HTTPResponse::HTTP_SEE_OTHER ||
res.getStatus() == HTTPResponse::HTTP_TEMPORARY_REDIRECT);
if (moved)
{
resolvedURI.resolve(res.get("Location"));
delete pSession;
if (resolvedURI.getScheme() != "http") throw UnsupportedRedirectException(uri.toString());
++redirects;
throw URIRedirection(resolvedURI.toString());
}
else if (res.getStatus() == HTTPResponse::HTTP_OK)
{
return new HTTPResponseStream(rs, pSession);
}
else throw HTTPException(res.getReason(), uri.toString());
else if (res.getStatus() == HTTPResponse::HTTP_USEPROXY && !retry)
{
//The requested resource MUST be accessed through the proxy
//given by the Location field. The Location field gives the
//URI of the proxy. The recipient is expected to repeat this
//single request via the proxy. 305 responses MUST only be generated by origin servers.
// only use for one single request!
proxyUri.resolve(res.get("Location"));
delete pSession; pSession = 0;
retry = true; //only allow useproxy once
}
else
{
throw HTTPException(res.getReason(), uri.toString());
}
}
while (redirects < MAX_REDIRECTS);
while(retry);
throw HTTPException("Too many redirects", uri.toString());
}
catch (...)

View File

@@ -1,7 +1,7 @@
//
// SocketImpl.cpp
//
// $Id: //poco/svn/Net/src/SocketImpl.cpp#2 $
// $Id: //poco/svn/Net/src/SocketImpl.cpp#3 $
//
// Library: Net
// Package: Sockets
@@ -54,13 +54,15 @@ namespace Net {
SocketImpl::SocketImpl():
_sockfd(POCO_INVALID_SOCKET)
_sockfd(POCO_INVALID_SOCKET),
_blocking(true)
{
}
SocketImpl::SocketImpl(poco_socket_t sockfd):
_sockfd(sockfd)
_sockfd(sockfd),
_blocking(true)
{
}
@@ -718,6 +720,7 @@ void SocketImpl::setBlocking(bool flag)
{
int arg = flag ? 0 : 1;
ioctl(FIONBIO, arg);
_blocking = flag;
}