Пример #1
0
void Pillow::HttpClient::sendRequest()
{
	if (!responsePending()) return;

	if (_hostHeaderValue.isEmpty())
	{
        _hostHeaderValue = _request.url.host(QUrl::FullyEncoded).toUtf8();
		if (_request.url.port(80) != 80)
		{
			_hostHeaderValue.append(':');
			Pillow::ByteArrayHelpers::appendNumber<int, 10>(_hostHeaderValue, _request.url.port(80));
		}
	}

    QByteArray uri = _request.url.path(QUrl::FullyEncoded).toUtf8();
    const QByteArray query = _request.url.query(QUrl::FullyEncoded).toUtf8();
	if (!query.isEmpty()) uri.append('?').append(query);

	Pillow::HttpHeaderCollection headers;
	headers.reserve(_request.headers.size() + 1);
	headers << Pillow::HttpHeader(Pillow::HttpClientTokens::hostToken, _hostHeaderValue);
	for (int i = 0, iE = _request.headers.size(); i < iE; ++i)
		headers << _request.headers.at(i);

	_requestWriter.write(_request.method, uri, headers, _request.data);
}
Пример #2
0
static QScriptValue toScriptValue(QScriptEngine *engine, const Pillow::HttpHeaderCollection &headers)
{
	QScriptValue result = engine->newObject();

	for (int i = 0, iE = headers.size(); i < iE; ++i)
		result.setProperty(QString::fromUtf8(headers.at(i).first), QUrl::fromPercentEncoding(headers.at(i).second));

	return result;
}
Пример #3
0
void Pillow::HttpHandlerProxyPipe::sendHeaders()
{
	if (_headersSent || _broken) return;
	_headersSent = true;

	// Headers have not been sent yet. Do so now.
	int statusCode = _proxiedReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
	QList<QPair<QByteArray, QByteArray> > headerList = _proxiedReply->rawHeaderPairs();
	Pillow::HttpHeaderCollection headers; headers.reserve(headerList.size());
	for (int i = 0, iE = headerList.size(); i < iE; ++i)
		headers << headerList.at(i);
	_request->writeHeaders(statusCode, headers);
}
Пример #4
0
void Pillow::HttpHandlerProxyPipe::sendHeaders()
{
	if (_headersSent || _broken) return;
	_headersSent = true;

	// Headers have not been sent yet. Do so now.
	int statusCode = _proxiedReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
	QList<Pillow::HttpHeader> headerList = _proxiedReply->rawHeaderPairs();
	Pillow::HttpHeaderCollection headers; headers.reserve(headerList.size());
	foreach (const Pillow::HttpHeader& header, headerList)
		headers << header;
	_request->writeHeaders(statusCode, headers);
}
Пример #5
0
void Pillow::HttpRequestWriter::write(const QByteArray &method, const QByteArray &path, const Pillow::HttpHeaderCollection &headers, const QByteArray &data)
{
	if (_device == 0)
	{
		qWarning() << "Pillow::HttpRequestWriter::write: called while device is not set. Not proceeding.";
		return;
	}

	if (_builder.capacity() < 8192)
		_builder.reserve(8192);

	_builder.append(method).append(' ').append(path).append(Pillow::HttpClientTokens::httpOneOneCrlfToken);

	for (const Pillow::HttpHeader *h = headers.constBegin(), *hE = headers.constEnd(); h < hE; ++h)
		_builder.append(h->first).append(Pillow::HttpClientTokens::colonSpaceToken).append(h->second).append(Pillow::HttpClientTokens::crlfToken);

	if (!data.isEmpty())
	{
		_builder.append(Pillow::HttpClientTokens::contentLengthColonSpaceToken);
		Pillow::ByteArrayHelpers::appendNumber<int, 10>(_builder, data.size());
		_builder.append(Pillow::HttpClientTokens::crlfToken);
	}

	_builder.append(Pillow::HttpClientTokens::crlfToken);

	if (data.isEmpty())
	{
		_device->write(_builder);
	}
	else
	{
		if (data.size() < 4096)
		{
			_builder.append(data);
			_device->write(_builder);
		}
		else
		{
			_device->write(_builder);
			_device->write(data);
		}
	}

	if (_builder.size() > 16384)
		_builder.clear();
	else
		_builder.data_ptr()->size = 0;
}
Пример #6
0
static void fromScriptValue(const QScriptValue &obj, Pillow::HttpHeaderCollection &headers)
{
	for (QScriptValueIterator it(obj); it.hasNext();)
	{
		it.next();
		headers.append(HttpHeader(it.name().toUtf8(), it.value().toString().toUtf8()));
	}
}