本文整理汇总了C++中THttpResponseHeader类的典型用法代码示例。如果您正苦于以下问题:C++ THttpResponseHeader类的具体用法?C++ THttpResponseHeader怎么用?C++ THttpResponseHeader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了THttpResponseHeader类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeResponse
qint64 TActionContext::writeResponse(int statusCode, THttpResponseHeader &header, const QByteArray &contentType, QIODevice *body, qint64 length)
{
T_TRACEFUNC("statusCode:%d contentType:%s length:%s", statusCode, contentType.data(), qPrintable(QString::number(length)));
header.setStatusLine(statusCode, THttpUtility::getResponseReasonPhrase(statusCode));
if (!contentType.isEmpty())
header.setContentType(contentType);
return writeResponse(header, body, length);
}
示例2: writeResponse
qint64 TActionContext::writeResponse(THttpResponseHeader &header, QIODevice *body, qint64 length)
{
T_TRACEFUNC("length:%s", qPrintable(QString::number(length)));
header.setContentLength(length);
header.setRawHeader("Server", "TreeFrog server");
header.setCurrentDate();
// Write data
return writeResponse(header, body);
}
示例3: writeResponse
qint64 TActionContext::writeResponse(THttpResponseHeader& header, QIODevice *body, qint64 length)
{
T_TRACEFUNC("length:%s", qPrintable(QString::number(length)));
qint64 res = -1;
if (httpSocket) {
header.setContentLength(length);
header.setRawHeader("Server", "TreeFrog server");
header.setRawHeader("Date", QLocale::c().toString(QDateTime::currentDateTime().toUTC(),
QLatin1String("ddd, dd MMM yyyy hh:mm:ss 'GMT'")).toLatin1());
header.setRawHeader("Connection", "close");
res = httpSocket->write(static_cast<THttpHeader*>(&header), body);
}
return res;
}
示例4: writeResponse
qint64 TActionWorker::writeResponse(THttpResponseHeader &header, QIODevice *body)
{
header.setRawHeader("Connection", "Keep-Alive");
accessLogger.setStatusCode(header.statusCode());
// Check auto-remove
bool autoRemove = false;
QFile *f = qobject_cast<QFile *>(body);
if (f) {
QString filePath = f->fileName();
if (TActionContext::autoRemoveFiles.contains(filePath)) {
TActionContext::autoRemoveFiles.removeAll(filePath);
autoRemove = true; // To remove after sent
}
}
if (!TActionContext::stopped) {
TEpollSocket::setSendData(socketId, static_cast<THttpHeader*>(&header), body, autoRemove, accessLogger);
}
accessLogger.close(); // not write in this thread
return 0;
}
示例5: sendHandshakeResponse
void TAbstractWebSocket::sendHandshakeResponse()
{
THttpResponseHeader response;
response.setStatusLine(Tf::SwitchingProtocols, THttpUtility::getResponseReasonPhrase(Tf::SwitchingProtocols));
response.setRawHeader("Upgrade", "websocket");
response.setRawHeader("Connection", "Upgrade");
QByteArray secAccept = QCryptographicHash::hash(reqHeader.rawHeader("Sec-WebSocket-Key").trimmed() + saltToken,
QCryptographicHash::Sha1).toBase64();
response.setRawHeader("Sec-WebSocket-Accept", secAccept);
writeRawData(response.toByteArray());
}
示例6: T_TRACEFUNC
void TActionContext::execute()
{
T_TRACEFUNC("");
THttpResponseHeader responseHeader;
accessLogger.open();
try {
if (!readRequest()) {
return;
}
const THttpRequestHeader &hdr = httpReq->header();
// Access log
accessLogger.setTimestamp(QDateTime::currentDateTime());
QByteArray firstLine = hdr.method() + ' ' + hdr.path();
firstLine += QString(" HTTP/%1.%2").arg(hdr.majorVersion()).arg(hdr.minorVersion()).toLatin1();
accessLogger.setRequest(firstLine);
accessLogger.setRemoteHost( (Tf::app()->appSettings().value(LISTEN_PORT).toUInt() > 0) ? clientAddress().toString().toLatin1() : QByteArray("(unix)") );
tSystemDebug("method : %s", hdr.method().data());
tSystemDebug("path : %s", hdr.path().data());
Tf::HttpMethod method = httpReq->method();
QString path = THttpUtility::fromUrlEncoding(hdr.path().mid(0, hdr.path().indexOf('?')));
// Routing info exists?
TRouting rt = TUrlRoute::instance().findRouting(method, path);
tSystemDebug("Routing: controller:%s action:%s", rt.controller.data(),
rt.action.data());
if (rt.isEmpty()) {
// Default URL routing
rt.params = path.split('/');
if (path.startsWith(QLatin1Char('/')) && !rt.params.isEmpty()) {
rt.params.removeFirst(); // unuse first item
}
if (path.endsWith(QLatin1Char('/')) && !rt.params.isEmpty()) {
rt.params.removeLast(); // unuse last item
}
// Direct view render mode?
if (Tf::app()->appSettings().value(DIRECT_VIEW_RENDER_MODE).toBool()) {
// Direct view setting
rt.controller = "directcontroller";
rt.action = "show";
} else {
if (!rt.params.value(0).isEmpty()) {
rt.controller = rt.params.takeFirst().toLower().toLatin1() + "controller";
if (rt.controller == "applicationcontroller") {
rt.controller.clear(); // Can not call 'ApplicationController'
}
// Default action: index
rt.action = rt.params.value(0, QLatin1String("index")).toLatin1();
if (!rt.params.isEmpty()) {
rt.params.takeFirst();
}
}
tSystemDebug("Active Controller : %s", rt.controller.data());
}
}
// Call controller method
TDispatcher<TActionController> ctlrDispatcher(rt.controller);
currController = ctlrDispatcher.object();
if (currController) {
currController->setActionName(rt.action);
// Session
if (currController->sessionEnabled()) {
TSession session;
QByteArray sessionId = httpReq->cookie(TSession::sessionName());
if (!sessionId.isEmpty()) {
// Finds a session
session = TSessionManager::instance().findSession(sessionId);
}
currController->setSession(session);
// Exports flash-variant
currController->exportAllFlashVariants();
}
// Verify authenticity token
if (Tf::app()->appSettings().value(ENABLE_CSRF_PROTECTION_MODULE, true).toBool()
&& currController->csrfProtectionEnabled() && !currController->exceptionActionsOfCsrfProtection().contains(rt.action)) {
if (method == Tf::Post || method == Tf::Put || method == Tf::Delete) {
if (!currController->verifyRequest(*httpReq)) {
throw SecurityException("Invalid authenticity token", __FILE__, __LINE__);
}
}
}
if (currController->sessionEnabled()) {
if (currController->session().id().isEmpty() || Tf::app()->appSettings().value(AUTO_ID_REGENERATION).toBool()) {
TSessionManager::instance().remove(currController->session().sessionId); // Removes the old session
// Re-generate session ID
currController->session().sessionId = TSessionManager::instance().generateId();
tSystemDebug("Re-generate session ID: %s", currController->session().sessionId.data());
//.........这里部分代码省略.........
示例7: writeResponse
qint64 TActionForkProcess::writeResponse(THttpResponseHeader &header, QIODevice *body)
{
header.setRawHeader("Connection", "Keep-Alive");
return httpSocket->write(static_cast<THttpHeader*>(&header), body);
}