CopperSpice API
1.9.2
|
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager. More...
Public Types | |
enum | Attribute |
enum | CacheLoadControl |
enum | KnownHeaders |
enum | LoadControl |
enum | Priority |
Public Methods | |
QNetworkRequest (const QNetworkRequest &other) | |
QNetworkRequest (const QUrl &url=QUrl ()) | |
~QNetworkRequest () | |
QVariant | attribute (Attribute code, const QVariant &defaultValue=QVariant ()) const |
bool | hasRawHeader (const QByteArray &headerName) const |
QVariant | header (KnownHeaders header) const |
int | maximumRedirectsAllowed () const |
bool | operator!= (const QNetworkRequest &other) const |
QNetworkRequest & | operator= (const QNetworkRequest &other) |
QNetworkRequest & | operator= (QNetworkRequest &&other) |
bool | operator== (const QNetworkRequest &other) const |
QObject * | originatingObject () const |
Priority | priority () const |
QByteArray | rawHeader (const QByteArray &headerName) const |
QList< QByteArray > | rawHeaderList () const |
void | setAttribute (Attribute code, const QVariant &value) |
void | setHeader (KnownHeaders header, const QVariant &value) |
void | setMaximumRedirectsAllowed (int maxRedirectsAllowed) |
void | setOriginatingObject (QObject *object) |
void | setPriority (Priority priority) |
void | setRawHeader (const QByteArray &headerName, const QByteArray &headerValue) |
void | setSslConfiguration (const QSslConfiguration &configuration) |
void | setUrl (const QUrl &url) |
QSslConfiguration | sslConfiguration () const |
void | swap (QNetworkRequest &other) |
QUrl | url () const |
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
QNetworkRequest is part of the Network Access API and is the class holding the information necessary to send a request over the network. It contains a URL and some ancillary information that can be used to modify the request.
Attribute codes for the QNetworkRequest and QNetworkReply.
Attributes are extra meta data that are used to control the behavior of the request and to pass further information from the reply back to the application. Attributes are also extensible, allowing custom implementations to pass custom values.
The following table explains what the default attribute codes are, the QVariant types associated, the default value if said attribute is missing and whether it is used in requests or replies.
Constant | Value | Description |
---|---|---|
QNetworkRequest::HttpStatusCodeAttribute | 0 | Replies only, type: QVariant::Int (no default) Indicates the HTTP status code received from the HTTP server (like 200, 304, 404, 401, etc.). If the connection was not HTTP-based, this attribute will not be present. |
QNetworkRequest::HttpReasonPhraseAttribute | 1 | Replies only, type: QVariant::ByteArray (no default) Indicates the HTTP reason phrase as received from the HTTP server (like "Ok", "Found", "Not Found", "Access Denied", etc.) This is the human readable representation of the status code (see above). If the connection was not HTTP-based, this attribute will not be present. |
QNetworkRequest::RedirectionTargetAttribute | 2 | Replies only, type: QVariant::Url (no default) If present, it indicates that the server is redirecting the request to a different URL. The Network Access API does not by default follow redirections: it's up to the application to determine if the requested redirection should be allowed, according to its security policies. The returned URL might be relative. Use QUrl::resolved() to create an absolute URL out of it. |
QNetworkRequest::ConnectionEncryptedAttribute | 3 | Replies only, type: QVariant::Bool (default: false) Indicates whether the data was obtained through an encrypted (secure) connection. |
QNetworkRequest::CacheLoadControlAttribute | 4 | Requests only, type: QVariant::Int (default: QNetworkRequest::PreferNetwork) Controls how the cache should be accessed. The possible values are those of QNetworkRequest::CacheLoadControl. Note that the default QNetworkAccessManager implementation does not support caching. However, this attribute may be used by certain backends to modify their requests (for example, for caching proxies). |
QNetworkRequest::CacheSaveControlAttribute | 5 | Requests only, type: QVariant::Bool (default: true) Controls if the data obtained should be saved to cache for future uses. If the value is false, the data obtained will not be automatically cached. If true, data may be cached, provided it is cacheable (what is cacheable depends on the protocol being used). |
QNetworkRequest::SourceIsFromCacheAttribute | 6 | Replies only, type: QVariant::Bool (default: false) Indicates whether the data was obtained from cache or not. |
QNetworkRequest::DoNotBufferUploadDataAttribute | 7 | Requests only, type: QVariant::Bool (default: false) Indicates whether the QNetworkAccessManager code is allowed to buffer the upload data, e.g. when doing a HTTP POST. When using this flag with sequential upload data, the ContentLengthHeader header must be set. |
QNetworkRequest::HttpPipeliningAllowedAttribute | 8 | Requests only, type: QVariant::Bool (default: false) Indicates whether the QNetworkAccessManager code is allowed to use HTTP pipelining with this request. |
QNetworkRequest::HttpPipeliningWasUsedAttribute | 9 | Replies only, type: QVariant::Bool Indicates whether the HTTP pipelining was used for receiving this reply. |
QNetworkRequest::CustomVerbAttribute | 10 | Requests only, type: QVariant::ByteArray Holds the value for the custom HTTP verb to send (destined for usage of other verbs than GET, POST, PUT and DELETE). This verb is set when calling QNetworkAccessManager::sendCustomRequest(). |
QNetworkRequest::CookieLoadControlAttribute | 11 | Requests only, type: QVariant::Int (default: QNetworkRequest::Automatic) Indicates whether to send 'Cookie' headers in the request. This attribute is set to false by CsWebKit when creating a cross-origin XMLHttpRequest where withCredentials has not been set explicitly to true by the JavaScript which created the request. |
QNetworkRequest::AuthenticationReuseAttribute | 12 | Requests only, type: QVariant::Int (default: QNetworkRequest::Automatic) Indicates whether to use cached authorization credentials in the request, if available. If this is set to QNetworkRequest::Manual and the authentication mechanism is 'Basic' or 'Digest', CopperSpice will not send an 'Authorization' HTTP header with any cached credentials it may have for the request's URL. This attribute is set to QNetworkRequest::Manual by CsWebKit when creating a cross-origin XMLHttpRequest where withCredentials has not been set explicitly to true by the JavaScript that created the request. |
QNetworkRequest::CookieSaveControlAttribute | 13 | Requests only, type: QVariant::Int (default: QNetworkRequest::Automatic) Indicates whether to save 'Cookie' headers received from the server in reply to the request. This attribute is set to false by CsWebKit when creating a cross-origin XMLHttpRequest where withCredentials has not been set explicitly to true by the JavaScript that created the request. |
QNetworkRequest::BackgroundRequestAttribute | 17 | Type: QVariant::Bool (default: false) Indicates that this is a background transfer, rather than a user initiated transfer. Depending on the platform, background transfers may be subject to different policies. The QNetworkSession ConnectInBackground property will be set according to this attribute. |
QNetworkRequest::SpdyAllowedAttribute | 18 | Requests only, type: QVariant::Bool (default: false) Indicates whether the QNetworkAccessManager code is allowed to use SPDY with this request. This applies only to SSL requests, and depends on the server supporting SPDY. |
QNetworkRequest::SpdyWasUsedAttribute | 19 | Replies only, type: QVariant::Bool Indicates whether SPDY was used for receiving this reply. |
QNetworkRequest::EmitAllUploadProgressSignalsAttribute | 20 | Requests only, type: QVariant::Bool (default: false) Indicates whether all upload signals should be emitted. By default, the uploadProgress signal is emitted only in 100 millisecond intervals. |
QNetworkRequest::FollowRedirectsAttribute | 21 | Requests only, type: QVariant::Bool (default: false) Indicates whether the Network Access API should automatically follow a HTTP redirect response or not. Currently redirects that are insecure, that is redirecting from "https" to "http" protocol, are not allowed. |
QNetworkRequest::User | 1000 | Special type. Additional information can be passed in QVariant with types ranging from User to UserMax. The default implementation of Network Access will ignore any request attributes in this range and it will not produce any attributes in this range in replies. The range is reserved for extensions of QNetworkAccessManager. |
QNetworkRequest::UserMax | 32767 | Special type, see user |
Controls the caching mechanism of QNetworkAccessManager.
Constant | Value | Description |
---|---|---|
QNetworkRequest::AlwaysNetwork | 0 | Always load from network and do not check if the cache has a valid entry (similar to the "Reload" feature in browsers) |
QNetworkRequest::PreferNetwork | 1 | Default value; load from the network if the cached entry is older than the network entry |
QNetworkRequest::PreferCache | 2 | Load from cache if available, otherwise load from network. Note that this can return possibly stale (but not expired) items from cache. |
QNetworkRequest::AlwaysCache | 3 | Only load from cache, indicating error if the item was not cached (i.e., off-line mode) |
List of known header types that QNetworkRequest parses. Each known header is also represented in raw form with its full HTTP name.
Constant | Value | Description |
---|---|---|
QNetworkRequest::ContentTypeHeader | 0 | Corresponds to HTTP Content-Type header and contains a string containing the media (MIME) type and any auxiliary data (for instance, charset) |
QNetworkRequest::ContentLengthHeader | 1 | Corresponds to HTTP Content-Length header and contains the length in bytes of the data transmitted |
QNetworkRequest::LocationHeader | 2 | Corresponds to HTTP Location header and contains a URL representing the actual location of the data, including the destination URL in case of redirections |
QNetworkRequest::LastModifiedHeader | 3 | Corresponds to HTTP Last-Modified header and contains a QDateTime representing the last modification date of the contents |
QNetworkRequest::CookieHeader | 4 | Corresponds to HTTP Cookie header and contains a QList<QNetworkCookie> representing the cookies to be sent back to the server |
QNetworkRequest::SetCookieHeader | 5 | Corresponds to the HTTP Set-Cookie header and contains a QList<QNetworkCookie> representing the cookies sent by the server to be stored locally |
QNetworkRequest::ContentDispositionHeader | 6 | Corresponds to HTTP Content-Disposition header and contains a string containing the disposition type (for instance, attachment) and a parameter (for instance, filename) |
QNetworkRequest::UserAgentHeader | 7 | User Agent header sent by HTTP clients |
QNetworkRequest::ServerHeader | 8 | Server header received by HTTP clients |
Indicates if an aspect of the request's loading mechanism has been manually overridden, for example CsWebKit.
Constant | Value | Description |
---|---|---|
QNetworkRequest::Automatic | 0 | default value: indicates default behavior. |
QNetworkRequest::Manual | 1 | indicates behavior has been manually overridden. |
This enum lists the possible network request priorities.
Constant | Value | Description |
---|---|---|
QNetworkRequest::HighPriority | 1 | High priority |
QNetworkRequest::NormalPriority | 3 | Normal priority |
QNetworkRequest::LowPriority | 5 | Low priority |
QNetworkRequest::QNetworkRequest | ( | const QNetworkRequest & | other | ) |
Creates a copy of other.
QNetworkRequest::~QNetworkRequest | ( | ) |
Disposes of the QNetworkRequest object.
QVariant QNetworkRequest::attribute | ( | Attribute | code, |
const QVariant & | defaultValue = QVariant() |
||
) | const |
Returns the attribute associated with the given code. If the attribute has not been set, it returns defaultValue. This methods does not apply the defaults listed in QNetworkRequest::Attribute.
bool QNetworkRequest::hasRawHeader | ( | const QByteArray & | headerName | ) | const |
Returns true if the raw header headerName is present in this network request.
QVariant QNetworkRequest::header | ( | KnownHeaders | header | ) | const |
Returns the value of the known network header if it is present in this request. If it is not present, returns an empty QVariant().
int QNetworkRequest::maximumRedirectsAllowed | ( | ) | const |
Returns the maximum number of redirects allowed to be followed for this request.
|
inline |
Returns false if this object is not the same as other.
QNetworkRequest & QNetworkRequest::operator= | ( | const QNetworkRequest & | other | ) |
Copy assigns from other and returns a reference to this object.
|
inline |
Move assigns from other and returns a reference to this object.
bool QNetworkRequest::operator== | ( | const QNetworkRequest & | other | ) | const |
Returns true if this object is the same as other (i.e., if they have the same URL, same headers and same meta data settings).
QObject * QNetworkRequest::originatingObject | ( | ) | const |
Returns a reference to the object that initiated this network request; returns 0 if not set or the object has been destroyed.
Priority QNetworkRequest::priority | ( | ) | const |
Return the priority of this request.
QByteArray QNetworkRequest::rawHeader | ( | const QByteArray & | headerName | ) | const |
Returns the raw form of header headerName. If no such header is present, an empty QByteArray is returned, which may be indistinguishable from a header that is present but has no content (use hasRawHeader() to find out if the header exists or not).
Raw headers can be set with setRawHeader() or with setHeader().
QList< QByteArray > QNetworkRequest::rawHeaderList | ( | ) | const |
Returns a list of all raw headers that are set in this network request. The list is in the order that the headers were set.
Sets the attribute associated with the given code to the specified value. If the attribute is already set the previous value is discarded. If value is an empty QVariant, the attribute is unset.
void QNetworkRequest::setHeader | ( | KnownHeaders | header, |
const QVariant & | value | ||
) |
Sets the value of the known header to the given value, overriding any previously set headers. This operation also sets the equivalent raw HTTP header.
void QNetworkRequest::setMaximumRedirectsAllowed | ( | int | maxRedirectsAllowed | ) |
Sets the maximum number of redirects allowed to be followed for this request to maxRedirectsAllowed.
void QNetworkRequest::setOriginatingObject | ( | QObject * | object | ) |
Allows setting a reference to the object initiating the request. For example CsWebKit sets the originating object to the QWebFrame that initiated the request.
void QNetworkRequest::setPriority | ( | Priority | priority | ) |
Set the priority of this request to priority. The priority is only a hint to the network access manager. It can use it or not. Currently it is used for HTTP to decide which request should be sent first to a server.
void QNetworkRequest::setRawHeader | ( | const QByteArray & | headerName, |
const QByteArray & | headerValue | ||
) |
Sets the header headerName to be of value headerValue. If headerName corresponds to a known header (see QNetworkRequest::KnownHeaders), the raw format will be parsed and the corresponding "cooked" header will be set as well.
will also set the known header LastModifiedHeader to be the QDateTime object of the parsed date.
Note: setting the same header twice overrides the previous setting. To accomplish the behavior of multiple HTTP headers of the same name, you should concatenate the two values, separating them with a comma (",") and set one single raw header.
void QNetworkRequest::setSslConfiguration | ( | const QSslConfiguration & | configuration | ) |
Sets this network request's SSL configuration to be config. The settings that apply are the private key, the local certificate, the SSL protocol (SSLv2, SSLv3, TLSv1 where applicable), the CA certificates and the ciphers that the SSL backend is allowed to use.
By default, no SSL configuration is set, which allows the backends to choose freely what configuration is best for them.
void QNetworkRequest::setUrl | ( | const QUrl & | url | ) |
Sets the URL for this network request to url.
QSslConfiguration QNetworkRequest::sslConfiguration | ( | ) | const |
Returns this network request's SSL configuration. By default, no SSL settings are specified.
|
inline |
Swaps this network request with other. This method is very fast and never fails.