Make https regexes static.

This commit is contained in:
Arthur Britto
2012-04-03 20:48:23 -07:00
parent 232bf4e2b8
commit 545c170d34
2 changed files with 17 additions and 14 deletions

View File

@@ -7,11 +7,10 @@
#include <iostream>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/regex.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/system/error_code.hpp>
#include <boost/regex.hpp>
using namespace boost::system;
using namespace boost::asio;
@@ -283,27 +282,30 @@ void HttpsClient::invokeComplete(const boost::system::error_code& ecResult, std:
void HttpsClient::parseData()
{
// AHB How does this work?
// http://stackoverflow.com/questions/877652/copy-a-streambufs-contents-to-a-string
std::string strData((std::istreambuf_iterator<char>(&mResponse)), std::istreambuf_iterator<char>());
// Match status code on a line.
boost::regex reStatus("\\`HTTP/1\\S+ (\\d{3}) .*\\'"); // HTTP/1.1 200 OK
// Match body.
boost::regex reBody("\\`(?:.*\\r\\n\\r\\n){1,1}(.*)\\'");
static boost::regex reStatus("\\`HTTP/1\\S+ (\\d{3}) .*\\'"); // HTTP/1.1 200 OK
static boost::regex reBody("\\`(?:.*?\\r\\n\\r\\n){1}(.*)\\'");
boost::smatch smMatch;
bool bMatch = boost::regex_match(strData, smMatch, reStatus)
bool bMatch = boost::regex_match(strData, smMatch, reStatus) // Match status code.
&& !smMatch[1].compare("200")
&& boost::regex_match(strData, smMatch, reBody);
&& boost::regex_match(strData, smMatch, reBody); // Match body.
std::cerr << "Match: " << bMatch << std::endl;
std::cerr << "Body:" << smMatch[1] << std::endl;
boost::system::error_code noErr;
if (bMatch)
{
boost::system::error_code noErr;
invokeComplete(noErr, smMatch[1]);
invokeComplete(noErr, smMatch[1]);
}
else
{
// XXX Use our own error code.
invokeComplete(boost::system::error_code(errc::bad_address, system_category()));
}
}
// vim:ts=4

View File

@@ -6,9 +6,10 @@
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
//
// Async https client.