PDA

View Full Version : Need ideas on implementing multi-https requests in my library



bull3t
6th January 2017, 18:05
Hi, I need your suggestions on an implementation problem I have. I'm coding an application that gets data from a site (not mine).

I splitted the client and the library. The whole works this way (briefly):

* the client queries the ApiRequest class for one of the site features and gets back an object for that feature, waiting for a signal from it; for instance:


loginCheck = api->loginCheck();
connect( loginCheck, SIGNAL(finished()), ... );
connect( loginCheck, SIGNAL(parseError()), ... );
connect( loginCheck, SIGNAL(requestError(QNetworkReply::NetworkError)), ... );

* ApiRequest is a static class instanced this way:


ApiRequest::ApiRequest()
{
nam = new QNetworkAccessManager;
requestHandler = new RequestHandler(nam);
}

with a series of functions, like:


LoginCheck * ApiRequest::loginCheck( )
{
...
QNetworkReply *reply;
reply = requestHandler->getRequest( requestUrl );

LoginCheck * loginCheck( new LoginCheck( reply ) );
return loginCheck;
}

* RequestHandler returns a QNetworkReply for the request:


QNetworkReply* RequestHandler::getRequest( const QString& url )
{
QUrl reqUrl( url );
QNetworkRequest request( reqUrl );
QNetworkReply* reply = nam->get( request );
return reply;
}

All this is working fine when each request needs only one QNetworkRequest. The problem is with the login feature that requires, in a row, GET, POST, REDIRECT, GET, REDIRECT, REDIRECT... I know, the site must be very dumb.

The problem is that with current implementation the object returned from ApiRequest essentially parses the output from the first GET request, and can't build new requests itself. I could put the chain of requests in the client but I prefer avoiding this ugly solution.

Do you have any suggestion? Do I have to rethink all the library?

Thanks for your time.

anda_skoa
10th January 2017, 08:43
When you create the LoginCheck instance, just also pass "this", i.e. the ApiRequest object.

That way LoginCheck can initiate further requests.

Cheers,
_