writeErrorHandler:
if (writeError == 1) {
- if (toApp) {
- NGBufferedDescriptor_free(toApp);
- toApp = NULL;
- }
+ if (toApp) NGBufferedDescriptor_free(toApp);
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server,
"socket write error during transfer of HTTP header section");
if (!NGBufferedDescriptor_safeWrite(toApp,
requestBody,
requestContentLength)) {
- if (toApp) {
- NGBufferedDescriptor_free(toApp);
- toApp = NULL;
- }
+ if (toApp) NGBufferedDescriptor_free(toApp);
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server,
"couldn't transfer HTTP req body to app server (%i bytes)",
contentLength);
/* read response line */
if (!NGScanResponseLine(toApp, NULL, &statusCode, NULL)) {
- if (toApp) {
- NGBufferedDescriptor_free(toApp);
- toApp = NULL;
- }
+ if (toApp) NGBufferedDescriptor_free(toApp);
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server,
"error during reading of response line ..");
return 500;
}
// read whole response
- NGBufferedDescriptor_safeRead(toApp, buffer, contentLength);
+ if (!NGBufferedDescriptor_safeRead(toApp, buffer, contentLength)) {
+ if (toApp != NULL) { NGBufferedDescriptor_free(toApp); toApp = NULL; }
+ }
+ // close connection to app
+ if (toApp != NULL) { NGBufferedDescriptor_free(toApp); toApp = NULL; }
+
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, r->server,
"send response (size=%i)",
contentLength);
int result = 0;
int writeCount = 0;
- while ((result = NGBufferedDescriptor_read(toApp,
- buffer,
- sizeof(buffer))
- > 0)) {
- ap_rwrite(buffer, result, r);
- ap_rflush(r);
- writeCount += result;
+ do {
+ result = NGBufferedDescriptor_read(toApp, buffer, sizeof(buffer));
+ if (result > 0) {
+ ap_rwrite(buffer, result, r);
+ ap_rflush(r);
+ writeCount += result;
+ }
}
+ while (result > 0);
if (HEAVY_LOG && (writeCount > 0)) {
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, r->server,
}
}
}
-
- // close connection to app
- if (toApp) {
- NGBufferedDescriptor_free(toApp);
- toApp = NULL;
- }
-
+
return OK;
}