Skip to content

Commit ab390ec

Browse files
bugfix of status-code of access log.
1 parent 3f60f44 commit ab390ec

File tree

2 files changed

+25
-30
lines changed

2 files changed

+25
-30
lines changed

.github/workflows/actions.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,6 @@ jobs:
183183
- name: testall.sh
184184
run: |
185185
$GITHUB_WORKSPACE/src/test/testall.sh
186-
- name: tmaketest
187-
run: |
188-
cd $GITHUB_WORKSPACE/tools/tmake/test
189-
qmake tmaketest.pro
190-
make -j4
191-
./tmaketest.sh
192186
- name: releasetest
193187
run: |
194188
$GITHUB_WORKSPACE/tools/test/releasetest/releasetest

src/tactioncontext.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ void TActionContext::execute(THttpRequest &request)
9999

100100
if (!route.exists) {
101101
// Default URL routing
102+
102103
if (Q_UNLIKELY(directViewRenderMode())) { // Direct view render mode?
103104
// Direct view setting
104105
route.setRouting(QByteArrayLiteral("directcontroller"), QByteArrayLiteral("show"), components);
@@ -170,12 +171,11 @@ void TActionContext::execute(THttpRequest &request)
170171
// Dispatches
171172
bool inv = ctlrDispatcher.invoke(route.action, route.params);
172173
if (!inv) {
173-
int bytes = writeResponse(Tf::NotFound, responseHeader);
174-
accessLogger.setResponseBytes(bytes);
174+
_currController->setStatusCode(Tf::NotFound);
175175
}
176176
}
177177

178-
// Flushes response
178+
// Flushes response and sets access log
179179
flushResponse(_currController, false);
180180

181181
// Session
@@ -188,7 +188,9 @@ void TActionContext::execute(THttpRequest &request)
188188
}
189189

190190
} else {
191-
accessLogger.setStatusCode(Tf::BadRequest); // Set a default status code
191+
// If no controller
192+
int responseBytes = 0;
193+
192194
if (route.controller.startsWith('/')) {
193195
path = route.controller;
194196
}
@@ -215,39 +217,37 @@ void TActionContext::execute(THttpRequest &request)
215217
// Sends a request file
216218
responseHeader.setRawHeader(QByteArrayLiteral("Last-Modified"), THttpUtility::toHttpDateTimeString(fi.lastModified()));
217219
QByteArray type = Tf::app()->internetMediaType(fi.suffix());
218-
int bytes = writeResponse(Tf::OK, responseHeader, type, &reqPath, reqPath.size());
219-
accessLogger.setResponseBytes(bytes);
220+
responseBytes = writeResponse(Tf::OK, responseHeader, type, &reqPath, reqPath.size());
220221
} else {
221222
// Not send the data
222-
int bytes = writeResponse(Tf::NotModified, responseHeader);
223-
accessLogger.setResponseBytes(bytes);
223+
responseBytes = writeResponse(Tf::NotModified, responseHeader);
224224
}
225225
} else {
226226
if (!route.exists) {
227-
int bytes = writeResponse(Tf::NotFound, responseHeader);
228-
accessLogger.setResponseBytes(bytes);
227+
responseBytes = writeResponse(Tf::NotFound, responseHeader);
229228
} else {
230229
// Routing not empty, redirect.
231230
responseHeader.setRawHeader(QByteArrayLiteral("Location"), QUrl(path).toEncoded());
232231
responseHeader.setContentType(QByteArrayLiteral("text/html"));
233-
int bytes = writeResponse(Tf::Found, responseHeader);
234-
accessLogger.setResponseBytes(bytes);
232+
responseBytes = writeResponse(Tf::Found, responseHeader);
235233
}
236234
}
237-
accessLogger.setStatusCode(responseHeader.statusCode());
238235

239236
} else if (method == Tf::Post) {
240-
// file upload?
237+
responseBytes = writeResponse(Tf::BadRequest, responseHeader);
241238
} else {
242-
// HEAD, DELETE, ...
239+
responseBytes = writeResponse(Tf::BadRequest, responseHeader);
243240
}
241+
242+
accessLogger.setResponseBytes(responseBytes);
243+
accessLogger.setStatusCode(responseHeader.statusCode());
244244
}
245245

246246
} catch (ClientErrorException &e) {
247247
tWarn("Caught %s: status code:%d", qUtf8Printable(e.className()), e.statusCode());
248248
tSystemWarn("Caught %s: status code:%d", qUtf8Printable(e.className()), e.statusCode());
249-
int bytes = writeResponse(e.statusCode(), responseHeader);
250-
accessLogger.setResponseBytes(bytes);
249+
int responseBytes = writeResponse(e.statusCode(), responseHeader);
250+
accessLogger.setResponseBytes(responseBytes);
251251
accessLogger.setStatusCode(e.statusCode());
252252
} catch (TfException &e) {
253253
tError("Caught %s: %s [%s:%d]", qUtf8Printable(e.className()), qUtf8Printable(e.message()), qUtf8Printable(e.fileName()), e.lineNumber());
@@ -294,7 +294,7 @@ void TActionContext::flushResponse(TActionController *controller, bool immediate
294294
return maxagestr.toInt();
295295
}());
296296

297-
if (!controller || controller->_rendered != TActionController::RenderState::Rendered) {
297+
if (!controller) {
298298
return;
299299
}
300300

@@ -394,20 +394,21 @@ void TActionContext::flushResponse(TActionController *controller, bool immediate
394394
}
395395

396396
// Sets the default status code of HTTP response
397-
int bytes = 0;
397+
int responseBytes = 0;
398398
if (Q_UNLIKELY(controller->_response.isBodyNull())) {
399-
accessLogger.setStatusCode(Tf::NotFound);
400399
THttpResponseHeader header;
401-
bytes = writeResponse(Tf::NotFound, header);
400+
responseBytes = writeResponse(Tf::NotFound, header);
401+
accessLogger.setStatusCode(header.statusCode());
402+
402403
} else {
403-
accessLogger.setStatusCode(controller->statusCode());
404404
controller->_response.header().setStatusLine(controller->statusCode(), THttpUtility::getResponseReasonPhrase(controller->statusCode()));
405405

406406
// Writes a response and access log
407407
int64_t bodyLength = (controller->_response.header().contentLength() > 0) ? controller->_response.header().contentLength() : controller->response().bodyLength();
408-
bytes = writeResponse(controller->_response.header(), controller->_response.bodyIODevice(), bodyLength);
408+
responseBytes = writeResponse(controller->_response.header(), controller->_response.bodyIODevice(), bodyLength);
409+
accessLogger.setStatusCode(controller->statusCode());
409410
}
410-
accessLogger.setResponseBytes(bytes);
411+
accessLogger.setResponseBytes(responseBytes);
411412

412413
if (immediate) {
413414
flushSocket();

0 commit comments

Comments
 (0)