fixed GH #1472: HTTP(S)StreamFactory should send a User-Agent header

This commit is contained in:
Guenter Obiltschnig
2016-10-26 12:58:52 +02:00
parent 1f3b53298c
commit 5df7f69b08
2 changed files with 16 additions and 0 deletions

View File

@@ -26,6 +26,8 @@
#include "Poco/UnbufferedStreamBuf.h" #include "Poco/UnbufferedStreamBuf.h"
#include "Poco/NullStream.h" #include "Poco/NullStream.h"
#include "Poco/StreamCopier.h" #include "Poco/StreamCopier.h"
#include "Poco/Format.h"
#include "Poco/Version.h"
using Poco::URIStreamFactory; using Poco::URIStreamFactory;
@@ -115,6 +117,12 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
cred.authenticate(req, res); cred.authenticate(req, res);
} }
req.set("User-Agent", Poco::format("poco/%d.%d.%d",
(POCO_VERSION >> 24) & 0xFF,
(POCO_VERSION >> 16) & 0xFF,
(POCO_VERSION >> 8) & 0xFF));
req.set("Accept", "*/*");
pSession->sendRequest(req); pSession->sendRequest(req);
std::istream& rs = pSession->receiveResponse(res); std::istream& rs = pSession->receiveResponse(res);
bool moved = (res.getStatus() == HTTPResponse::HTTP_MOVED_PERMANENTLY || bool moved = (res.getStatus() == HTTPResponse::HTTP_MOVED_PERMANENTLY ||

View File

@@ -26,6 +26,8 @@
#include "Poco/UnbufferedStreamBuf.h" #include "Poco/UnbufferedStreamBuf.h"
#include "Poco/NullStream.h" #include "Poco/NullStream.h"
#include "Poco/StreamCopier.h" #include "Poco/StreamCopier.h"
#include "Poco/Format.h"
#include "Poco/Version.h"
using Poco::URIStreamFactory; using Poco::URIStreamFactory;
@@ -118,6 +120,12 @@ std::istream* HTTPSStreamFactory::open(const URI& uri)
cred.authenticate(req, res); cred.authenticate(req, res);
} }
req.set("User-Agent", Poco::format("poco/%d.%d.%d",
(POCO_VERSION >> 24) & 0xFF,
(POCO_VERSION >> 16) & 0xFF,
(POCO_VERSION >> 8) & 0xFF));
req.set("Accept", "*/*");
pSession->sendRequest(req); pSession->sendRequest(req);
std::istream& rs = pSession->receiveResponse(res); std::istream& rs = pSession->receiveResponse(res);
bool moved = (res.getStatus() == HTTPResponse::HTTP_MOVED_PERMANENTLY || bool moved = (res.getStatus() == HTTPResponse::HTTP_MOVED_PERMANENTLY ||