2 #include <QNetworkRequest>
53 this, SLOT(
sslErrors(QNetworkReply*,QList<QSslError>)) );
55 _timer.setSingleShot(
true);
56 connect( &
_timer, SIGNAL(timeout()),
65 QTimer::singleShot( 0,
this, SLOT(
expire()) );
92 return _url.toString( QUrl::FullyEncoded );
192 QNetworkRequest request(
_url);
193 request.setAttribute(QNetworkRequest::FollowRedirectsAttribute,
true);
240 data = reply->readAll();
243 QJsonObject jsondata =
_json ? QJsonDocument::fromJson(data).object() : QJsonObject { {
"data",QString(data)} };
244 QJsonObject jsondiff;
271 if (!jsondiff.isEmpty())
273 r->
_data.setObject(jsondiff);
292 reply->deleteLater();
364 QList<QByteArray> headers = reply->rawHeaderList();
365 foreach (QByteArray h,headers)
366 m[QString(h)] = QString(reply->rawHeader(h));
382 for (
int i=0;i<errors.size();i++)
bool _stale
If the retrieved content is stale. Initialized as true.
virtual void read(VFS_request *r)
Request the _url.
bool _json
Interpret fetched data as json.
virtual void sslErrors(QNetworkReply *, const QList< QSslError > &errors)
One or more ssl errors have occurred.
QNetworkReply * _request
The outstanding request, if any.
QJsonObject _data
The data retrieved from a http get request after it has been sent to parse().
virtual bool isContainer()
A VFS_curl node cannot contain children.
bool _poll
If data is considered expired, re-request it.
virtual QByteArray icon()
The "stream" icon found in the VFS_icons library.
virtual QString reportDetails()
Report the url.
virtual void expire()
Set the _stale value to true, and if _poll, request an update.
int _timeout
The time to wait for a response before timing out. Defaults to 60000 ms = 1 minute.
QJsonObject getHeaders(QNetworkReply *reply)
Create a QJsonObject based on a QNetworkReply.
virtual void get(VFS_request *r)
VFS_curl::get.
Q_INVOKABLE VFS_curl(QString url, bool json=false, bool poll=false, int expire=10000, int timeout=60000)
virtual void networkTimeout()
A request was initiated, but timed out.
void replyFinished(QNetworkReply *reply)
A network request has completed.
QTimer _timer
For detecting timeouts on network requests. The QNetworkAccessManager doesn't do this on its own.
QString _reason
If an http request was invalid, this will contain the error string.
QList< VFS_request * > _requests
A list of outstanding VFS_request objects to satisfy once an http request is complete.
virtual QJsonObject parse(QJsonObject data, QJsonObject &diffout)
Parse the incoming data into useful format.
bool _valid
If the http request was valid.
QNetworkAccessManager _manager
The http request manager.
int _expire
Time in milliseconds to consider the retrieved data stale.
QJsonObject _metadata
Certain headers returned from a successful http get request.
bool _getting
If an outstanding request exists.
QUrl _url
The url to request.
virtual void metadata(VFS_request *r)
Fetch the metadata for this node.
static char * get(QString which="")
Fetch an icon from the library.
VFS_node is the base class from which all other VFS_node classes derive.
virtual VFS_request * createRequest(VFS_request::requestType type, QString path, QString user="unknown", QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool dontDelete=false)
Create a new VFS_request with this object as _origin.
virtual void issueResponse(VFS_request *t)
Once a request has been completed, issue a response.
virtual void metadata(VFS_request *r)
Fetch the metadata of this node.
void diff(VFS_node *origin, VFS_request *t)
Emit a diff, which will trigger notifySubscribers() for a mounted node.
QString className()
Return the class name of a node.
void finished(bool andDelete=false)
Emitted if a thread fails to create its node, or a node is rm()'d, or any other reason a node has com...
The base class for all requests between nodes.
@ read
read full contents (4)
@ metadata
read metadata (6)
@ subscribe
subscribe to a path (9)
requestType _requestType
the action this request is performing or requesting
QString _reason
if something (probably bad) happened, this is the reason
bool _isCallback
whether or not to issue a response (IE, another request is chained to this request,...
bool _success
if the request was successfully completed
QJsonDocument _data
the request payload
QJsonObject _metadata
the request payload
static void LOG(QString message, int level=0, QString user="server")
Send a message to the VFS::_messages VFS_stream.
static void ERROR(QString message, int level=0, QString user="server")
Send a message to the VFS::_errors VFS_stream.
static void WARN(QString message, int level=0, QString user="server")
Send a message to the VFS::_warnings VFS_stream.