1
/***************************************************************************
2
qgshttptransaction.h - Tracks a HTTP request with its response,
3
with particular attention to tracking
4
HTTP redirect responses
7
copyright : (C) 2005 by Brendan Morley
8
email : morb at ozemail dot com dot au
9
***************************************************************************/
11
/***************************************************************************
13
* This program is free software; you can redistribute it and/or modify *
14
* it under the terms of the GNU General Public License as published by *
15
* the Free Software Foundation; either version 2 of the License, or *
16
* (at your option) any later version. *
18
***************************************************************************/
20
/* $Id: qgshttptransaction.h 5697 2006-08-15 10:29:46Z morb_au $ */
22
#ifndef QGSHTTPTRANSACTION_H
23
#define QGSHTTPTRANSACTION_H
32
\brief HTTP request/response manager that is redirect-aware.
34
This class extends the Qt QHttp concept by being able to recognise
35
and respond to redirection responses (e.g. HTTP code 302)
42
class QgsHttpTransaction : public QObject
51
QgsHttpTransaction( QString uri,
52
QString proxyHost = QString(),
54
QString proxyUser = QString(),
55
QString proxyPass = QString() );
58
virtual ~QgsHttpTransaction();
60
void getAsynchronously();
62
//! Gets the response synchronously. Note that signals will still be emitted
63
//! while in this function.
66
The function returns FALSE if there is an error while getting the response.
67
\param[out] respondedContent is replaced with the new content.
68
\param[in] redirections is used to measure how many http redirections we've been through.
69
Clients typically don't need to set this.
71
bool getSynchronously(QByteArray &respondedContent, int redirections = 0);
73
QString responseContentType();
76
* If an operation returns 0 (e.g. getSynchronously()), this function
77
* returns the text of the error associated with the failure.
78
* Interactive users of this provider can then, for example,
79
* call a QMessageBox to display the contents.
81
QString errorString();
86
void dataStarted( int id );
88
void dataHeaderReceived( const QHttpResponseHeader& resp );
90
void dataReceived( const QHttpResponseHeader& resp );
92
void dataProgress( int done, int total );
94
void dataFinished( int id, bool error );
96
void transactionFinished( bool error );
98
void dataStateChanged( int state );
100
void networkTimedOut();
104
/** \brief emit a signal to notify of a progress event */
105
void setProgress(int theProgress, int theTotalSteps);
107
/** \brief emit a signal to be caught by qgisapp and display a msg on status bar */
108
void setStatus(QString theStatusQString);
114
* Indicates the associated QHttp object
116
* \note We tried to use this as a plain QHttp object
117
* but strange things were happening with the signals -
118
* therefore we use the "pointer to" instead.
123
* Indicates the QHttp ID
128
* Indicates if the transaction is in progress
133
* Indicates the response from the QHttp
135
QByteArray httpresponse;
138
* Indicates the content type of the response from the QHttp
140
QString httpresponsecontenttype;
143
* The original URL requested for this transaction
148
* The host being used for this transaction
153
* The port being used for this transaction
158
* The username being used for this transaction
163
* The password being used for this transaction
168
* If not empty, indicates that the QHttp is a redirect
169
* to the contents of this variable
171
QString httpredirecturl;
174
* Number of http redirections this transaction has been
177
* TODO: Use this as part of a redirection loop detector
180
int httpredirections;
183
* Indicates the associated QTimer object - used to detect network timeouts
185
QTimer * mWatchdogTimer;
188
* The error message associated with the last HTTP error.