mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-28 19:51:58 +01:00
added https->http redirect, improved redirect support in streamfactory, fixed client cert validation error
This commit is contained in:
@@ -75,17 +75,25 @@ HTTPSStreamFactory::~HTTPSStreamFactory()
|
||||
|
||||
std::istream* HTTPSStreamFactory::open(const URI& uri)
|
||||
{
|
||||
poco_assert (uri.getScheme() == "https");
|
||||
poco_assert (uri.getScheme() == "https" || uri.getScheme() == "http");
|
||||
|
||||
URI resolvedURI(uri);
|
||||
URI proxyUri;
|
||||
HTTPClientSession* pSession = 0;
|
||||
try
|
||||
{
|
||||
bool retry = false;
|
||||
int redirects = 0;
|
||||
do
|
||||
{
|
||||
pSession = new HTTPSClientSession(resolvedURI.getHost(), resolvedURI.getPort());
|
||||
pSession->setProxy(_proxyHost, _proxyPort);
|
||||
if (resolvedURI.getScheme() != "http")
|
||||
pSession = new HTTPSClientSession(resolvedURI.getHost(), resolvedURI.getPort());
|
||||
else
|
||||
pSession = new HTTPClientSession(resolvedURI.getHost(), resolvedURI.getPort());
|
||||
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);
|
||||
@@ -94,20 +102,38 @@ std::istream* HTTPSStreamFactory::open(const URI& uri)
|
||||
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_SEE_OTHER ||
|
||||
res.getStatus() == HTTPResponse::HTTP_TEMPORARY_REDIRECT);
|
||||
if (moved)
|
||||
{
|
||||
resolvedURI.resolve(res.get("Location"));
|
||||
delete pSession;
|
||||
//throw URIRedirection(resolvedURI.toString());
|
||||
delete pSession; pSession = 0;
|
||||
++redirects;
|
||||
retry = true;
|
||||
}
|
||||
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
|
||||
{
|
||||
delete pSession; pSession = 0;
|
||||
throw HTTPException(res.getReason(), uri.toString());
|
||||
}
|
||||
}
|
||||
while (redirects < MAX_REDIRECTS);
|
||||
while (retry && redirects < MAX_REDIRECTS);
|
||||
throw HTTPException("Too many redirects", uri.toString());
|
||||
}
|
||||
catch (...)
|
||||
|
||||
Reference in New Issue
Block a user