qnetworkrequest.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtNetwork module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QNETWORKREQUEST_H
  40. #define QNETWORKREQUEST_H
  41. #include <QtCore/QSharedDataPointer>
  42. #include <QtCore/QString>
  43. #include <QtCore/QUrl>
  44. #include <QtCore/QVariant>
  45. QT_BEGIN_NAMESPACE
  46. class QSslConfiguration;
  47. class QNetworkRequestPrivate;
  48. class Q_NETWORK_EXPORT QNetworkRequest
  49. {
  50. public:
  51. enum KnownHeaders {
  52. ContentTypeHeader,
  53. ContentLengthHeader,
  54. LocationHeader,
  55. LastModifiedHeader,
  56. CookieHeader,
  57. SetCookieHeader,
  58. ContentDispositionHeader, // added for QMultipartMessage
  59. UserAgentHeader,
  60. ServerHeader
  61. };
  62. enum Attribute {
  63. HttpStatusCodeAttribute,
  64. HttpReasonPhraseAttribute,
  65. RedirectionTargetAttribute,
  66. ConnectionEncryptedAttribute,
  67. CacheLoadControlAttribute,
  68. CacheSaveControlAttribute,
  69. SourceIsFromCacheAttribute,
  70. DoNotBufferUploadDataAttribute,
  71. HttpPipeliningAllowedAttribute,
  72. HttpPipeliningWasUsedAttribute,
  73. CustomVerbAttribute,
  74. CookieLoadControlAttribute,
  75. AuthenticationReuseAttribute,
  76. CookieSaveControlAttribute,
  77. MaximumDownloadBufferSizeAttribute, // internal
  78. DownloadBufferAttribute, // internal
  79. SynchronousRequestAttribute, // internal
  80. BackgroundRequestAttribute,
  81. SpdyAllowedAttribute,
  82. SpdyWasUsedAttribute,
  83. EmitAllUploadProgressSignalsAttribute,
  84. FollowRedirectsAttribute,
  85. User = 1000,
  86. UserMax = 32767
  87. };
  88. enum CacheLoadControl {
  89. AlwaysNetwork,
  90. PreferNetwork,
  91. PreferCache,
  92. AlwaysCache
  93. };
  94. enum LoadControl {
  95. Automatic = 0,
  96. Manual
  97. };
  98. enum Priority {
  99. HighPriority = 1,
  100. NormalPriority = 3,
  101. LowPriority = 5
  102. };
  103. explicit QNetworkRequest(const QUrl &url = QUrl());
  104. QNetworkRequest(const QNetworkRequest &other);
  105. ~QNetworkRequest();
  106. #ifdef Q_COMPILER_RVALUE_REFS
  107. QNetworkRequest &operator=(QNetworkRequest &&other) Q_DECL_NOTHROW { swap(other); return *this; }
  108. #endif
  109. QNetworkRequest &operator=(const QNetworkRequest &other);
  110. void swap(QNetworkRequest &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
  111. bool operator==(const QNetworkRequest &other) const;
  112. inline bool operator!=(const QNetworkRequest &other) const
  113. { return !operator==(other); }
  114. QUrl url() const;
  115. void setUrl(const QUrl &url);
  116. // "cooked" headers
  117. QVariant header(KnownHeaders header) const;
  118. void setHeader(KnownHeaders header, const QVariant &value);
  119. // raw headers:
  120. bool hasRawHeader(const QByteArray &headerName) const;
  121. QList<QByteArray> rawHeaderList() const;
  122. QByteArray rawHeader(const QByteArray &headerName) const;
  123. void setRawHeader(const QByteArray &headerName, const QByteArray &value);
  124. // attributes
  125. QVariant attribute(Attribute code, const QVariant &defaultValue = QVariant()) const;
  126. void setAttribute(Attribute code, const QVariant &value);
  127. #ifndef QT_NO_SSL
  128. QSslConfiguration sslConfiguration() const;
  129. void setSslConfiguration(const QSslConfiguration &configuration);
  130. #endif
  131. void setOriginatingObject(QObject *object);
  132. QObject *originatingObject() const;
  133. Priority priority() const;
  134. void setPriority(Priority priority);
  135. // HTTP redirect related
  136. int maximumRedirectsAllowed() const;
  137. void setMaximumRedirectsAllowed(int maximumRedirectsAllowed);
  138. private:
  139. QSharedDataPointer<QNetworkRequestPrivate> d;
  140. friend class QNetworkRequestPrivate;
  141. };
  142. Q_DECLARE_SHARED(QNetworkRequest)
  143. QT_END_NAMESPACE
  144. Q_DECLARE_METATYPE(QNetworkRequest)
  145. #endif