本文整理汇总了C++中HttpHeaders::removeAll方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpHeaders::removeAll方法的具体用法?C++ HttpHeaders::removeAll怎么用?C++ HttpHeaders::removeAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders::removeAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: respond
void respond(int code, const QByteArray &reason, const HttpHeaders &headers, const QByteArray &body)
{
if(state != WriteBody)
return;
HttpHeaders outHeaders = headers;
outHeaders.removeAll("Connection");
outHeaders.removeAll("Transfer-Encoding");
outHeaders.removeAll("Content-Length");
outHeaders += HttpHeader("Connection", "close");
outHeaders += HttpHeader("Content-Length", QByteArray::number(body.size()));
QByteArray respData = "HTTP/";
if(version1dot0)
respData += "1.0 ";
else
respData += "1.1 ";
respData += QByteArray::number(code) + " " + reason + "\r\n";
foreach(const HttpHeader &h, outHeaders)
respData += h.first + ": " + h.second + "\r\n";
respData += "\r\n";
respData += body;
state = WaitForWritten;
pendingWritten += respData.size();
sock->write(respData);
}
示例2: tryApplyJsonp
// return true if jsonp applied
bool tryApplyJsonp(const DomainMap::JsonpConfig &config, bool *ok, QString *errorMessage)
{
*ok = true;
// must be a GET
if(requestData.method != "GET")
return false;
QString callbackParam = QString::fromUtf8(config.callbackParam);
if(callbackParam.isEmpty())
callbackParam = "callback";
QString bodyParam;
if(!config.bodyParam.isEmpty())
bodyParam = QString::fromUtf8(config.bodyParam);
QUrl uri = requestData.uri;
QUrlQuery query(uri);
// two ways to activate JSON-P:
// 1) callback param present
// 2) default callback specified in configuration and body param present
if(!query.hasQueryItem(callbackParam) &&
(config.defaultCallback.isEmpty() || bodyParam.isEmpty() || !query.hasQueryItem(bodyParam)))
{
return false;
}
QByteArray callback;
if(query.hasQueryItem(callbackParam))
{
callback = parsePercentEncoding(query.queryItemValue(callbackParam, QUrl::FullyEncoded).toUtf8());
if(callback.isEmpty())
{
log_debug("requestsession: id=%s invalid callback parameter, rejecting", rid.second.data());
*ok = false;
*errorMessage = "Invalid callback parameter.";
return false;
}
query.removeAllQueryItems(callbackParam);
}
else
callback = config.defaultCallback;
QString method;
if(query.hasQueryItem("_method"))
{
method = QString::fromLatin1(parsePercentEncoding(query.queryItemValue("_method", QUrl::FullyEncoded).toUtf8()));
if(!validMethod(method))
{
log_debug("requestsession: id=%s invalid _method parameter, rejecting", rid.second.data());
*ok = false;
*errorMessage = "Invalid _method parameter.";
return false;
}
query.removeAllQueryItems("_method");
}
HttpHeaders headers;
if(query.hasQueryItem("_headers"))
{
QJsonParseError e;
QJsonDocument doc = QJsonDocument::fromJson(parsePercentEncoding(query.queryItemValue("_headers", QUrl::FullyEncoded).toUtf8()), &e);
if(e.error != QJsonParseError::NoError || !doc.isObject())
{
log_debug("requestsession: id=%s invalid _headers parameter, rejecting", rid.second.data());
*ok = false;
*errorMessage = "Invalid _headers parameter.";
return false;
}
QVariantMap headersMap = doc.object().toVariantMap();
QMapIterator<QString, QVariant> vit(headersMap);
while(vit.hasNext())
{
vit.next();
if(vit.value().type() != QVariant::String)
{
log_debug("requestsession: id=%s invalid _headers parameter, rejecting", rid.second.data());
*ok = false;
*errorMessage = "Invalid _headers parameter.";
return false;
}
QByteArray key = vit.key().toUtf8();
// ignore some headers that we explicitly set later on
if(qstricmp(key.data(), "host") == 0)
continue;
if(qstricmp(key.data(), "accept") == 0)
continue;
headers += HttpHeader(key, vit.value().toString().toUtf8());
}
//.........这里部分代码省略.........
示例3: start
//.........这里部分代码省略.........
{
log_warning("streamed input must start with seq 0");
QMetaObject::invokeMethod(this, "respondError", Qt::QueuedConnection, Q_ARG(QByteArray, "bad-request"));
return;
}
// can't use these two together
if(mode == Worker::Single && request.more)
{
log_warning("cannot use streamed input on router interface");
QMetaObject::invokeMethod(this, "respondError", Qt::QueuedConnection, Q_ARG(QByteArray, "bad-request"));
return;
}
bodySent = false;
inSeq = request.seq;
if(!isAllowed(request.uri.host()) || (!request.connectHost.isEmpty() && !isAllowed(request.connectHost)))
{
QMetaObject::invokeMethod(this, "respondError", Qt::QueuedConnection, Q_ARG(QByteArray, "policy-violation"));
return;
}
QByteArray hostHeader = request.uri.host().toUtf8();
// only tack on the port if it isn't being overridden
int port = request.uri.port(defaultPort);
if(request.connectPort == -1 && port != defaultPort)
hostHeader += ":" + QByteArray::number(port);
headers.removeAll("Host");
headers += HttpHeader("Host", hostHeader);
hreq = new HttpRequest(dns, this);
connect(hreq, SIGNAL(nextAddress(const QHostAddress &)), SLOT(req_nextAddress(const QHostAddress &)));
connect(hreq, SIGNAL(readyRead()), SLOT(req_readyRead()));
connect(hreq, SIGNAL(bytesWritten(int)), SLOT(req_bytesWritten(int)));
connect(hreq, SIGNAL(error()), SLOT(req_error()));
maxResponseSize = request.maxSize;
sessionTimeout = request.timeout;
if(!request.connectHost.isEmpty())
hreq->setConnectHost(request.connectHost);
if(request.connectPort != -1)
request.uri.setPort(request.connectPort);
hreq->setIgnoreTlsErrors(request.ignoreTlsErrors);
if(request.followRedirects)
hreq->setFollowRedirects(8);
if(request.credits != -1)
outCredits += request.credits;
}
else // WebSocketTransport
{
log_info("IN id=%s, %s", request.id.data(), request.uri.toEncoded().data());
// inbound streaming must start with sequence number of 0
if(request.seq != 0)
{
log_warning("websocket input must start with seq 0");