Qt 4.8
Public Functions | Static Public Functions | Public Variables | List of all members
QHttpNetworkRequestPrivate Class Reference

#include <qhttpnetworkrequest_p.h>

Inheritance diagram for QHttpNetworkRequestPrivate:
QHttpNetworkHeaderPrivate QSharedData

Public Functions

QByteArray methodName () const
 
bool operator== (const QHttpNetworkRequestPrivate &other) const
 
 QHttpNetworkRequestPrivate (QHttpNetworkRequest::Operation op, QHttpNetworkRequest::Priority pri, const QUrl &newUrl=QUrl())
 
 QHttpNetworkRequestPrivate (const QHttpNetworkRequestPrivate &other)
 
QByteArray uri (bool throughProxy) const
 
 ~QHttpNetworkRequestPrivate ()
 
- Public Functions inherited from QHttpNetworkHeaderPrivate
qint64 contentLength () const
 
QByteArray headerField (const QByteArray &name, const QByteArray &defaultValue=QByteArray()) const
 
QList< QByteArrayheaderFieldValues (const QByteArray &name) const
 
bool operator== (const QHttpNetworkHeaderPrivate &other) const
 
 QHttpNetworkHeaderPrivate (const QUrl &newUrl=QUrl())
 
 QHttpNetworkHeaderPrivate (const QHttpNetworkHeaderPrivate &other)
 
void setContentLength (qint64 length)
 
void setHeaderField (const QByteArray &name, const QByteArray &data)
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 

Static Public Functions

static QByteArray header (const QHttpNetworkRequest &request, bool throughProxy)
 

Public Variables

bool autoDecompress
 
QByteArray customVerb
 
QHttpNetworkRequest::Operation operation
 
bool pipeliningAllowed
 
QHttpNetworkRequest::Priority priority
 
bool ssl
 
QNonContiguousByteDeviceuploadByteDevice
 
bool withCredentials
 
- Public Variables inherited from QHttpNetworkHeaderPrivate
QList< QPair< QByteArray, QByteArray > > fields
 
QUrl url
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Definition at line 132 of file qhttpnetworkrequest_p.h.

Constructors and Destructors

◆ QHttpNetworkRequestPrivate() [1/2]

QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate ( QHttpNetworkRequest::Operation  op,
QHttpNetworkRequest::Priority  pri,
const QUrl newUrl = QUrl() 
)

Definition at line 49 of file qhttpnetworkrequest.cpp.

53 {
54 }
QHttpNetworkHeaderPrivate(const QUrl &newUrl=QUrl())
QHttpNetworkRequest::Operation operation
QHttpNetworkRequest::Priority priority
QNonContiguousByteDevice * uploadByteDevice

◆ QHttpNetworkRequestPrivate() [2/2]

QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate ( const QHttpNetworkRequestPrivate other)

Definition at line 56 of file qhttpnetworkrequest.cpp.

◆ ~QHttpNetworkRequestPrivate()

QHttpNetworkRequestPrivate::~QHttpNetworkRequestPrivate ( )

Definition at line 69 of file qhttpnetworkrequest.cpp.

70 {
71 }

Functions

◆ header()

QByteArray QHttpNetworkRequestPrivate::header ( const QHttpNetworkRequest request,
bool  throughProxy 
)
static

Definition at line 135 of file qhttpnetworkrequest.cpp.

Referenced by QHttpNetworkConnectionChannel::pipelineInto(), and QHttpNetworkConnectionChannel::sendRequest().

136 {
138  QByteArray ba;
139  ba.reserve(40 + fields.length()*25); // very rough lower bound estimation
140 
141  ba += request.d->methodName();
142  ba += ' ';
143  ba += request.d->uri(throughProxy);
144 
145  ba += " HTTP/";
146  ba += QByteArray::number(request.majorVersion());
147  ba += '.';
148  ba += QByteArray::number(request.minorVersion());
149  ba += "\r\n";
150 
151  QList<QPair<QByteArray, QByteArray> >::const_iterator it = fields.constBegin();
152  QList<QPair<QByteArray, QByteArray> >::const_iterator endIt = fields.constEnd();
153  for (; it != endIt; ++it) {
154  ba += it->first;
155  ba += ": ";
156  ba += it->second;
157  ba += "\r\n";
158  }
159  if (request.d->operation == QHttpNetworkRequest::Post) {
160  // add content type, if not set in the request
161  if (request.headerField("content-type").isEmpty()) {
162  //Content-Type is mandatory. We can't say anything about the encoding, but x-www-form-urlencoded is the most likely to work.
163  //This warning indicates a bug in application code not setting a required header.
164  //Note that if using QHttpMultipart, the content-type is set in QNetworkAccessManagerPrivate::prepareMultipart already
165  qWarning("content-type missing in HTTP POST, defaulting to application/x-www-form-urlencoded. Use QNetworkRequest::setHeader() to fix this problem.");
166  ba += "Content-Type: application/x-www-form-urlencoded\r\n";
167  }
168  if (!request.d->uploadByteDevice && request.d->url.hasQuery()) {
169  QByteArray query = request.d->url.encodedQuery();
170  ba += "Content-Length: ";
171  ba += QByteArray::number(query.size());
172  ba += "\r\n\r\n";
173  ba += query;
174  } else {
175  ba += "\r\n";
176  }
177  } else {
178  ba += "\r\n";
179  }
180  return ba;
181 }
QSharedDataPointer< QHttpNetworkRequestPrivate > d
#define it(className, varName)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
bool hasQuery() const
Returns true if this URL contains a Query (i.
Definition: qurl.cpp:5058
QList< QPair< QByteArray, QByteArray > > header() const
QByteArray headerField(const QByteArray &name, const QByteArray &defaultValue=QByteArray()) const
QList< QPair< QByteArray, QByteArray > > fields
Q_CORE_EXPORT void qWarning(const char *,...)
QHttpNetworkRequest::Operation operation
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
int length() const
This function is identical to count().
Definition: qlist.h:281
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QByteArray uri(bool throughProxy) const
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449
QNonContiguousByteDevice * uploadByteDevice
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
QByteArray encodedQuery() const
Returns the query string of the URL in percent encoded form.
Definition: qurl.cpp:5643
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ methodName()

QByteArray QHttpNetworkRequestPrivate::methodName ( ) const

Definition at line 81 of file qhttpnetworkrequest.cpp.

Referenced by QHttpNetworkConnectionPrivate::createAuthorization(), and header().

82 {
83  switch (operation) {
85  return "GET";
86  break;
88  return "HEAD";
89  break;
91  return "POST";
92  break;
94  return "OPTIONS";
95  break;
97  return "PUT";
98  break;
100  return "DELETE";
101  break;
103  return "TRACE";
104  break;
106  return "CONNECT";
107  break;
109  return customVerb;
110  break;
111  default:
112  break;
113  }
114  return QByteArray();
115 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QHttpNetworkRequest::Operation operation

◆ operator==()

bool QHttpNetworkRequestPrivate::operator== ( const QHttpNetworkRequestPrivate other) const

Definition at line 73 of file qhttpnetworkrequest.cpp.

74 {
76  && (operation == other.operation)
77  && (ssl == other.ssl)
78  && (uploadByteDevice == other.uploadByteDevice);
79 }
QHttpNetworkRequest::Operation operation
bool operator==(const QHttpNetworkHeaderPrivate &other) const
QNonContiguousByteDevice * uploadByteDevice

◆ uri()

QByteArray QHttpNetworkRequestPrivate::uri ( bool  throughProxy) const

Definition at line 117 of file qhttpnetworkrequest.cpp.

Referenced by QHttpNetworkConnectionPrivate::createAuthorization(), and header().

118 {
119  QUrl::FormattingOptions format(QUrl::RemoveFragment);
120 
121  // for POST, query data is send as content
124  // for requests through proxy, the Request-URI contains full url
125  if (throughProxy)
127  else
130  if (uri.isEmpty() || (throughProxy && url.path().isEmpty()))
131  uri += '/';
132  return uri;
133 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QString path() const
Returns the path of the URL.
Definition: qurl.cpp:4977
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QHttpNetworkRequest::Operation operation
QByteArray toEncoded(FormattingOptions options=None) const
Returns the encoded representation of the URL if it&#39;s valid; otherwise an empty QByteArray is returne...
Definition: qurl.cpp:5949
QByteArray uri(bool throughProxy) const
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
QNonContiguousByteDevice * uploadByteDevice

Properties

◆ autoDecompress

bool QHttpNetworkRequestPrivate::autoDecompress

◆ customVerb

QByteArray QHttpNetworkRequestPrivate::customVerb

◆ operation

QHttpNetworkRequest::Operation QHttpNetworkRequestPrivate::operation

◆ pipeliningAllowed

bool QHttpNetworkRequestPrivate::pipeliningAllowed

◆ priority

QHttpNetworkRequest::Priority QHttpNetworkRequestPrivate::priority

◆ ssl

bool QHttpNetworkRequestPrivate::ssl

◆ uploadByteDevice

QNonContiguousByteDevice* QHttpNetworkRequestPrivate::uploadByteDevice
mutable

◆ withCredentials

bool QHttpNetworkRequestPrivate::withCredentials

The documentation for this class was generated from the following files: