Skip to content

Commit

Permalink
Fixed response ready signal. It was emitted multiple times.
Browse files Browse the repository at this point in the history
Added X-Client-Name and X-Client-Version headers.
  • Loading branch information
bnogalm committed Mar 29, 2019
1 parent 1f82f43 commit fe3bf2f
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 11 deletions.
4 changes: 4 additions & 0 deletions StellarQtSDK.pri
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ DEFINES += STELLAR_QT_REPLY_TIMEOUT=30000

DEFINES *= ED25519_NO_SEED

DEFINES += STELLAR_QT_SDK_CLIENT_NAME=\"\\\"qtcpp-stellar-sdk\\\"\"
DEFINES += STELLAR_QT_SDK_CLIENT_VERSION=\"\\\"0.1.8\\\"\"


QT *= core network
CONFIG *= c++11

Expand Down
2 changes: 1 addition & 1 deletion src/federation/federationserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ FederationServer::FederationServer(QString serverUri, QString domain) {
FederationServer *FederationServer::createForDomain(QString domain) {

if(s_cachedFederationServers){
FederationServer * cached = s_cachedFederationServers->value(domain,0);
FederationServer * cached = s_cachedFederationServers->value(domain,nullptr);
if(cached)
return cached;
}
Expand Down
5 changes: 4 additions & 1 deletion src/responses/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ PageBase *PageBase::getNextPage(){
return nullptr;
}
QNetworkAccessManager* manager = this->m_reply->manager();
QNetworkReply * reply = manager->get(QNetworkRequest(this->getLinks().getNext().getHref()));
QNetworkRequest request(this->getLinks().getNext().getHref());
request.setRawHeader("X-Client-Name", STELLAR_QT_SDK_CLIENT_NAME);
request.setRawHeader("X-Client-Version", STELLAR_QT_SDK_CLIENT_VERSION);
QNetworkReply * reply = manager->get(request);
this->loadFromReply(reply);
return this;//we reuse same object
}
5 changes: 4 additions & 1 deletion src/responses/response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ void Response::reconnectStreamDelayed()
QNetworkRequest request(m_reply->request());
if(!m_lastID.isEmpty())
request.setRawHeader("Last-Event-ID",m_lastID);
request.setRawHeader("X-Client-Name", STELLAR_QT_SDK_CLIENT_NAME);
request.setRawHeader("X-Client-Version", STELLAR_QT_SDK_CLIENT_VERSION);

QNetworkReply * reply = manager->get(request);
loadFromReply(reply);
}
Expand Down Expand Up @@ -204,7 +207,7 @@ bool Response::preprocessResponse(QNetworkReply *response)
m_rateLimitLimit =response->rawHeader("X-Ratelimit-Limit").toInt();
m_rateLimitRemaining =response->rawHeader("X-Ratelimit-Remaining").toInt();
m_rateLimitReset =response->rawHeader("X-Ratelimit-Reset").toInt();

emit rateLimitChanged();
// Too Many Requests
if (errorCode == 429) {
int retryAfter = response->rawHeader("Retry-After").toInt();
Expand Down
23 changes: 15 additions & 8 deletions src/responses/response.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ inline QList<T> convert(QVariantList source)
class Response : public QObject
{
Q_OBJECT
Q_PROPERTY(int rateLimitLimit READ getRateLimitLimit NOTIFY ready)
Q_PROPERTY(int rateLimitRemaining READ getRateLimitRemaining NOTIFY ready)
Q_PROPERTY(int rateLimitReset READ getRateLimitReset NOTIFY ready)
Q_PROPERTY(QString type MEMBER m_type NOTIFY ready)
Q_PROPERTY(QString title MEMBER m_title NOTIFY ready)
Q_PROPERTY(int status MEMBER m_status NOTIFY ready)
Q_PROPERTY(QString instance MEMBER m_instance NOTIFY ready)
Q_PROPERTY(QString detail MEMBER m_detail NOTIFY ready)
Q_PROPERTY(int rateLimitLimit READ getRateLimitLimit NOTIFY rateLimitChanged)
Q_PROPERTY(int rateLimitRemaining READ getRateLimitRemaining NOTIFY rateLimitChanged)
Q_PROPERTY(int rateLimitReset READ getRateLimitReset NOTIFY rateLimitChanged)
Q_PROPERTY(QString type MEMBER m_type NOTIFY typeChanged)
Q_PROPERTY(QString title MEMBER m_title NOTIFY titleChanged)
Q_PROPERTY(int status MEMBER m_status NOTIFY statusChanged)
Q_PROPERTY(QString instance MEMBER m_instance NOTIFY instanceChanged)
Q_PROPERTY(QString detail MEMBER m_detail NOTIFY detailChanged)


QString m_type;
Expand Down Expand Up @@ -73,6 +73,13 @@ class Response : public QObject
signals:
void ready();
void error();
void rateLimitChanged();
void typeChanged();
void titleChanged();
void statusChanged();
void instanceChanged();
void detailChanged();

private:
bool preprocessResponse(QNetworkReply *response);
void restartTimeoutTimer();
Expand Down
2 changes: 2 additions & 0 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ QNetworkRequest Server::prepareRequest()
{
QNetworkRequest request;
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
request.setRawHeader("X-Client-Name", STELLAR_QT_SDK_CLIENT_NAME);
request.setRawHeader("X-Client-Version", STELLAR_QT_SDK_CLIENT_VERSION);
return request;
}

Expand Down
2 changes: 2 additions & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Server : public QObject
QNetworkRequest request(rb->requestUri());
if(rb->streamMode())
request.setRawHeader("Accept","text/event-stream");
request.setRawHeader("X-Client-Name", STELLAR_QT_SDK_CLIENT_NAME);
request.setRawHeader("X-Client-Version", STELLAR_QT_SDK_CLIENT_VERSION);
QNetworkReply * r = m_httpClient->get(request);
auto response = new T(r);
response->setParent(this);//so it is not collected by QML
Expand Down
2 changes: 2 additions & 0 deletions test/servertest.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ private slots:

void initTestCase()
{
qDebug() <<"qtcpp stellar client name:"<<STELLAR_QT_SDK_CLIENT_NAME;
qDebug() <<"qtcpp stellar client version:"<< STELLAR_QT_SDK_CLIENT_VERSION;
this->setUp();
}
void cleanupTestCase()
Expand Down

0 comments on commit fe3bf2f

Please sign in to comment.