Skip to content

Instantly share code, notes, and snippets.

@karlr42
Created January 18, 2013 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlr42/4566844 to your computer and use it in GitHub Desktop.
Save karlr42/4566844 to your computer and use it in GitHub Desktop.
#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/StreamCopier.h>
#include <iostream>
/*
* Test case to show slow DNS lookup when making a request to a
* particular domain. The HTTP level in terms of the response
* is not that important- the actual lookup happens as part of
* creating a Net::SocketAddress in Net::HTTPClientSession::reconnect()
*
* Compiled with:
* g++ -o"PocoDNSTestCase" PocoDNSTestCase.cpp -lPocoUtil -lPocoNet
* and ran with : ./PocoDNSTestCase
*/
using namespace Poco::Net;
#define BROKEN_DOMAIN "word-view.beta.officeapps.live.com"
int main(int argc, char *argv[]){
//isolated test of the problem domain
HTTPClientSession hcs(BROKEN_DOMAIN);
// send request
HTTPRequest req(HTTPRequest::HTTP_GET, "/", HTTPMessage::HTTP_1_1);
hcs.sendRequest(req); //hangs here- DNS lookup takes a long time
// get response
HTTPResponse res;
std::cerr<< res.getStatus() << " " << res.getReason() << std::endl;
// print response
std::istream &is = hcs.receiveResponse(res);
Poco::StreamCopier::copyStream(is, std::cerr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment