handler.c (opengroupware-5.5rc2) | : | handler.c (opengroupware-5.5rc3) | ||
---|---|---|---|---|
skipping to change at line 31 | skipping to change at line 31 | |||
#include "common.h" | #include "common.h" | |||
#define BUFSIZE 2048 | #define BUFSIZE 2048 | |||
/* ap_http_method is deprecated in Apache 2.2.x */ | /* ap_http_method is deprecated in Apache 2.2.x */ | |||
#if MODULE_MAGIC_NUMBER_MAJOR >= 20051115 | #if MODULE_MAGIC_NUMBER_MAJOR >= 20051115 | |||
#define ap_http_method ap_http_scheme | #define ap_http_method ap_http_scheme | |||
#endif | #endif | |||
#ifdef APLOG_USE_MODULE | ||||
APLOG_USE_MODULE(ngobjweb); | ||||
#endif | ||||
extern int HEAVY_LOG; | extern int HEAVY_LOG; | |||
#if WITH_LOGGING | #if WITH_LOGGING | |||
static void _logTable(const char *text, apr_table_t *table); | static void _logTable(const char *text, apr_table_t *table); | |||
#endif | #endif | |||
static ngobjweb_dir_config *_getConfig(request_rec *r) { | static ngobjweb_dir_config *_getConfig(request_rec *r) { | |||
ngobjweb_dir_config *cfg; | ngobjweb_dir_config *cfg; | |||
if (r == NULL) { | if (r == NULL) { | |||
fprintf(stderr, "%s: missing request !\n", __PRETTY_FUNCTION__); | fprintf(stderr, "%s: missing request !\n", __PRETTY_FUNCTION__); | |||
return NULL; | return NULL; | |||
} | } | |||
if (r->per_dir_config == NULL) { | if (r->per_dir_config == NULL) { | |||
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, | |||
"missing directory config in request ..."); | "missing directory config in request ..."); | |||
return NULL; | return NULL; | |||
} | } | |||
cfg = (ngobjweb_dir_config *) | cfg = (ngobjweb_dir_config *) | |||
ap_get_module_config(r->per_dir_config, &ngobjweb_module); | ap_get_module_config(r->per_dir_config, &ngobjweb_module); | |||
return cfg; | return cfg; | |||
} | } | |||
skipping to change at line 97 | skipping to change at line 101 | |||
clen = apr_table_get(r->headers_in, "content-length"); | clen = apr_table_get(r->headers_in, "content-length"); | |||
contentLength = clen ? atoi(clen) : 0; | contentLength = clen ? atoi(clen) : 0; | |||
*requestContentLength = contentLength; | *requestContentLength = contentLength; | |||
/* no content to read ... */ | /* no content to read ... */ | |||
if (contentLength == 0) return NULL; | if (contentLength == 0) return NULL; | |||
/* read content */ | /* read content */ | |||
if (HEAVY_LOG) { | if (HEAVY_LOG) { | |||
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, | |||
"going to read %i bytes from browser ...", contentLength); | "going to read %i bytes from browser ...", contentLength); | |||
} | } | |||
requestBody = apr_palloc(r->pool, contentLength + 2); | requestBody = apr_palloc(r->pool, contentLength + 2); | |||
ptr = requestBody; | ptr = requestBody; | |||
for (toBeRead = contentLength; toBeRead > 0;) { | for (toBeRead = contentLength; toBeRead > 0;) { | |||
#ifdef AP_VERSION_1 | #ifdef AP_VERSION_1 | |||
readBytes = ap_bread(r->connection->client, ptr, toBeRead); | readBytes = ap_bread(r->connection->client, ptr, toBeRead); | |||
#else | #else | |||
ap_setup_client_block(r,REQUEST_CHUNKED_DECHUNK); | ap_setup_client_block(r,REQUEST_CHUNKED_DECHUNK); | |||
readBytes = ap_get_client_block(r, ptr, toBeRead); | readBytes = ap_get_client_block(r, ptr, toBeRead); | |||
#endif | #endif | |||
toBeRead -= readBytes; | toBeRead -= readBytes; | |||
ptr += readBytes; | ptr += readBytes; | |||
if (readBytes == 0) break; | if (readBytes == 0) break; | |||
} | } | |||
ptr = NULL; | ptr = NULL; | |||
if (toBeRead > 0) { | if (toBeRead > 0) { | |||
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, | |||
"couldn't read complete HTTP req body from browser " | "couldn't read complete HTTP req body from browser " | |||
"(read %i of %i bytes)", | "(read %i of %i bytes)", | |||
(contentLength - toBeRead), contentLength); | (contentLength - toBeRead), contentLength); | |||
return NULL; | return NULL; | |||
} | } | |||
return requestBody; | return requestBody; | |||
} | } | |||
static void | static void | |||
skipping to change at line 187 | skipping to change at line 191 | |||
char *ptr = NULL; | char *ptr = NULL; | |||
int port; | int port; | |||
char sport[256]; | char sport[256]; | |||
ptr = inet_ntoa(((struct sockaddr_in *)address)->sin_addr); | ptr = inet_ntoa(((struct sockaddr_in *)address)->sin_addr); | |||
port = ntohs(((struct sockaddr_in *)address)->sin_port); | port = ntohs(((struct sockaddr_in *)address)->sin_port); | |||
apr_snprintf(sport, sizeof(sport), "host=\"%s\" port=%i", ptr, port); | apr_snprintf(sport, sizeof(sport), "host=\"%s\" port=%i", ptr, port); | |||
strcat(buf, sport); | strcat(buf, sport); | |||
} | } | |||
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, r->server, buf); | ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, "%s", buf); | |||
} | } | |||
static int _connectInstance(request_rec *r, | static int _connectInstance(request_rec *r, | |||
int appFd, struct sockaddr *address, | int appFd, struct sockaddr *address, | |||
size_t addressLen) | size_t addressLen) | |||
{ | { | |||
int result; | int result; | |||
int tryCount = 0; | int tryCount = 0; | |||
char isConnected = 0; | char isConnected = 0; | |||
result = connect(appFd, address, addressLen); | result = connect(appFd, address, addressLen); | |||
if (result >= 0) return result; | if (result >= 0) return result; | |||
while (tryCount < 3) { | while (tryCount < 3) { | |||
char *pdelay = NULL; /* pblock_findval("delay", _paras) */ | char *pdelay = NULL; /* pblock_findval("delay", _paras) */ | |||
int delay = pdelay ? atoi(pdelay) : 3; // default: 3s | int delay = pdelay ? atoi(pdelay) : 3; // default: 3s | |||
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, | |||
"sleeping %is ..", delay); | "sleeping %is ..", delay); | |||
#ifdef AP_VERSION_1 | #ifdef AP_VERSION_1 | |||
apr_sleep(delay); /* should be in seconds for Apache 1? */ | apr_sleep(delay); /* should be in seconds for Apache 1? */ | |||
#else | #else | |||
apr_sleep(delay * 1000 * 1000 /* in microseconds now! */); | apr_sleep(delay * 1000 * 1000 /* in microseconds now! */); | |||
#endif | #endif | |||
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, | |||
"retry connect .."); | "retry connect .."); | |||
result = connect(appFd, address, addressLen); | result = connect(appFd, address, addressLen); | |||
if (result >= 0) { | if (result >= 0) { | |||
isConnected = 1; | isConnected = 1; | |||
break; | break; | |||
} | } | |||
tryCount++; | tryCount++; | |||
} | } | |||
if (isConnected == 0) { | if (isConnected == 0) { | |||
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, | |||
"connect to application instance failed, tried %i times.", | "connect to application instance failed, tried %i times.", | |||
tryCount); | tryCount); | |||
close(appFd); | close(appFd); | |||
return -1; | return -1; | |||
} | } | |||
return result; | return result; | |||
} | } | |||
static int _writeInHeaders(NGBufferedDescriptor *toApp, request_rec *r) { | static int _writeInHeaders(NGBufferedDescriptor *toApp, request_rec *r) { | |||
const apr_array_header_t *array; | const apr_array_header_t *array; | |||
skipping to change at line 291 | skipping to change at line 295 | |||
if (uri == NULL) return DECLINED; | if (uri == NULL) return DECLINED; | |||
if (uri[0] != '/') return DECLINED; | if (uri[0] != '/') return DECLINED; | |||
if (strstr(uri, "WebServerResources")) return DECLINED; | if (strstr(uri, "WebServerResources")) return DECLINED; | |||
/* get directory configuration */ | /* get directory configuration */ | |||
if ((cfg = _getConfig(r))) { | if ((cfg = _getConfig(r))) { | |||
if (cfg->appPrefix) { | if (cfg->appPrefix) { | |||
if (HEAVY_LOG) { | if (HEAVY_LOG) { | |||
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, | |||
"using prefix '%s'\n", cfg->appPrefix); | "using prefix '%s'\n", cfg->appPrefix); | |||
} | } | |||
uri += strlen(cfg->appPrefix); | uri += strlen(cfg->appPrefix); | |||
} | } | |||
} | } | |||
else { | else { | |||
return 500; | return 500; | |||
} | } | |||
/* find app name in url */ | /* find app name in url */ | |||
skipping to change at line 324 | skipping to change at line 328 | |||
if (cfg->snsPort) { | if (cfg->snsPort) { | |||
address = _sendSNSQuery(r, | address = _sendSNSQuery(r, | |||
r->the_request, | r->the_request, | |||
apr_table_get(r->headers_in, "cookie"), | apr_table_get(r->headers_in, "cookie"), | |||
&domain, &addressLen, | &domain, &addressLen, | |||
appName, | appName, | |||
cfg); | cfg); | |||
if (address == NULL) { | if (address == NULL) { | |||
/* did not find an appropriate application server */ | /* did not find an appropriate application server */ | |||
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, | |||
"did not find SOPE instance using SNS."); | "did not find SOPE instance using SNS."); | |||
return DECLINED; | return DECLINED; | |||
} | } | |||
} | } | |||
else if (cfg->appPort) { | else if (cfg->appPort) { | |||
domain = cfg->appPortDomain; | domain = cfg->appPortDomain; | |||
if (cfg->appPortDomain == AF_UNIX) { | if (cfg->appPortDomain == AF_UNIX) { | |||
addressLen = sizeof(struct sockaddr_un); | addressLen = sizeof(struct sockaddr_un); | |||
address = apr_palloc(r->pool, sizeof(struct sockaddr_un)); | address = apr_palloc(r->pool, sizeof(struct sockaddr_un)); | |||
skipping to change at line 360 | skipping to change at line 364 | |||
host[pos - cfg->appPort] = '\0'; | host[pos - cfg->appPort] = '\0'; | |||
port = atoi(pos + 1); | port = atoi(pos + 1); | |||
} | } | |||
else { | else { | |||
host = "127.0.0.1"; | host = "127.0.0.1"; | |||
port = atoi(cfg->appPort); | port = atoi(cfg->appPort); | |||
} | } | |||
#if HEAVY_LOG | #if HEAVY_LOG | |||
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, | |||
"appPort: '%s' host: %s port %d, cfg 0x%p", | "appPort: '%s' host: %s port %d, cfg 0x%p", | |||
cfg->appPort, host, port, cfg); | cfg->appPort, host, port, cfg); | |||
#endif | #endif | |||
addressLen = sizeof(struct sockaddr_in); | addressLen = sizeof(struct sockaddr_in); | |||
address = apr_palloc(r->pool, sizeof(struct sockaddr_in)); | address = apr_palloc(r->pool, sizeof(struct sockaddr_in)); | |||
memset(address, 0, sizeof(struct sockaddr_in)); | memset(address, 0, sizeof(struct sockaddr_in)); | |||
snsi = (struct sockaddr_in *)address; | snsi = (struct sockaddr_in *)address; | |||
snsi->sin_addr.s_addr = apr_inet_addr(host); | snsi->sin_addr.s_addr = apr_inet_addr(host); | |||
snsi->sin_family = AF_INET; | snsi->sin_family = AF_INET; | |||
snsi->sin_port = htons((short)(port & 0xFFFF)); | snsi->sin_port = htons((short)(port & 0xFFFF)); | |||
if (snsi->sin_addr.s_addr == -1) { | if (snsi->sin_addr.s_addr == -1) { | |||
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, | |||
"could not convert IP address: %s", host); | "could not convert IP address: %s", host); | |||
} | } | |||
if (HEAVY_LOG && 0) { | if (HEAVY_LOG && 0) { | |||
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, | |||
"connect IP address: %s", host); | "connect IP address: %s", host); | |||
} | } | |||
} | } | |||
} | } | |||
else { | else { | |||
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, | |||
"neither SNS port nor app port are set for request ..."); | "neither SNS port nor app port are set for request ..."); | |||
return 500; | return 500; | |||
} | } | |||
if (addressLen > 10000) { | if (addressLen > 10000) { | |||
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, | |||
"suspect instance port length (%li) ...", | "suspect instance port length (%li) ...", | |||
(long int) addressLen); | (long int) addressLen); | |||
return 500; | return 500; | |||
} | } | |||
_logInstanceAddress(r, address, addressLen, domain); | _logInstanceAddress(r, address, addressLen, domain); | |||
/* setup connection to application server */ | /* setup connection to application server */ | |||
if ((appFd = socket(domain, SOCK_STREAM, 0)) < 0) { | if ((appFd = socket(domain, SOCK_STREAM, 0)) < 0) { | |||
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, | |||
"could not create socket in domain %i.", domain); | "could not create socket in domain %i.", domain); | |||
return DECLINED; | return DECLINED; | |||
} | } | |||
if ((result = _connectInstance(r, appFd, address, addressLen)) < 0) | if ((result = _connectInstance(r, appFd, address, addressLen)) < 0) | |||
return 500; | return 500; | |||
toApp = NGBufferedDescriptor_newWithOwnedDescriptorAndSize(appFd, 512); | toApp = NGBufferedDescriptor_newWithOwnedDescriptorAndSize(appFd, 512); | |||
if (toApp == NULL) { | if (toApp == NULL) { | |||
close(appFd); | close(appFd); | |||
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, | |||
"could not alloc socket buffer for " | "could not alloc socket buffer for " | |||
"application server connection"); | "application server connection"); | |||
return 500; | return 500; | |||
} | } | |||
/* write request to application server */ | /* write request to application server */ | |||
if (HEAVY_LOG) { | if (HEAVY_LOG) { | |||
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, | |||
"transfer reqline"); | "transfer reqline"); | |||
} | } | |||
{ | { | |||
char *reqLine; | char *reqLine; | |||
unsigned toGo; | unsigned toGo; | |||
reqLine = r->the_request; | reqLine = r->the_request; | |||
toGo = reqLine ? strlen(reqLine) : 0; | toGo = reqLine ? strlen(reqLine) : 0; | |||
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, | |||
"req is %s(len=%i)", reqLine, toGo); | "req is %s(len=%i)", reqLine, toGo); | |||
if (!NGBufferedDescriptor_safeWrite(toApp, reqLine, | if (!NGBufferedDescriptor_safeWrite(toApp, reqLine, | |||
reqLine ? strlen(reqLine) : 0)) { | reqLine ? strlen(reqLine) : 0)) { | |||
writeError = 1; | writeError = 1; | |||
goto writeErrorHandler; | goto writeErrorHandler; | |||
} | } | |||
if (!NGBufferedDescriptor_safeWrite(toApp, "\r\n", 2)) { | if (!NGBufferedDescriptor_safeWrite(toApp, "\r\n", 2)) { | |||
writeError = 1; | writeError = 1; | |||
goto writeErrorHandler; | goto writeErrorHandler; | |||
} | } | |||
} | } | |||
/* transfer headers */ | /* transfer headers */ | |||
if (writeError == 0) { | if (writeError == 0) { | |||
if (HEAVY_LOG) { | if (HEAVY_LOG) { | |||
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, | |||
"transfer hdrs"); | "transfer hdrs"); | |||
} | } | |||
/* extended adaptor headers */ | /* extended adaptor headers */ | |||
{ | { | |||
char tmp[256]; | char tmp[256]; | |||
const char *value; | const char *value; | |||
value = r->protocol; | value = r->protocol; | |||
value = (value != NULL) ? value : "http"; | value = (value != NULL) ? value : "http"; | |||
if (!NGBufferedDescriptor_writeHttpHeader(toApp, | if (!NGBufferedDescriptor_writeHttpHeader(toApp, | |||
"x-webobjects-server-protocol", | "x-webobjects-server-protocol", | |||
(unsigned char *)value)) { | (unsigned char *)value)) { | |||
writeError = 1; | writeError = 1; | |||
goto writeErrorHandler; | goto writeErrorHandler; | |||
} | } | |||
if ((value = r->connection->remote_ip) != NULL) { | if ((value = r->connection->client_ip) != NULL) { | |||
if (!NGBufferedDescriptor_writeHttpHeader(toApp, | if (!NGBufferedDescriptor_writeHttpHeader(toApp, | |||
"x-webobjects-remote-addr", | "x-webobjects-remote-addr", | |||
(unsigned char *)value)) { | (unsigned char *)value)) { | |||
writeError = 1; | writeError = 1; | |||
goto writeErrorHandler; | goto writeErrorHandler; | |||
} | } | |||
} | } | |||
value = r->connection->remote_host; | value = r->connection->remote_host; | |||
if (value == NULL) value = r->connection->remote_ip; | if (value == NULL) value = r->connection->client_ip; | |||
if (value != NULL) { | if (value != NULL) { | |||
if (!NGBufferedDescriptor_writeHttpHeader(toApp, | if (!NGBufferedDescriptor_writeHttpHeader(toApp, | |||
"x-webobjects-remote-host", | "x-webobjects-remote-host", | |||
(unsigned char *)value)) { | (unsigned char *)value)) { | |||
writeError = 1; | writeError = 1; | |||
goto writeErrorHandler; | goto writeErrorHandler; | |||
} | } | |||
} | } | |||
#ifdef AP_VERSION_1 | #ifdef AP_VERSION_1 | |||
skipping to change at line 654 | skipping to change at line 658 | |||
writeError = 1; | writeError = 1; | |||
} | } | |||
writeErrorHandler: | writeErrorHandler: | |||
if (writeError == 1) { | if (writeError == 1) { | |||
if (toApp) { | if (toApp) { | |||
NGBufferedDescriptor_free(toApp); | NGBufferedDescriptor_free(toApp); | |||
toApp = NULL; | toApp = NULL; | |||
} | } | |||
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, | |||
"socket write error during transfer of HTTP header section"); | "socket write error during transfer of HTTP header section"); | |||
return 500; | return 500; | |||
} | } | |||
/* transfer request body */ | /* transfer request body */ | |||
if (requestContentLength > 0) { | if (requestContentLength > 0) { | |||
if (!NGBufferedDescriptor_safeWrite(toApp, | if (!NGBufferedDescriptor_safeWrite(toApp, | |||
requestBody, | requestBody, | |||
requestContentLength)) { | requestContentLength)) { | |||
if (toApp) { | if (toApp) { | |||
NGBufferedDescriptor_free(toApp); | NGBufferedDescriptor_free(toApp); | |||
toApp = NULL; | toApp = NULL; | |||
} | } | |||
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, | |||
"couldn't transfer HTTP req body to app server (%i bytes)", | "couldn't transfer HTTP req body to app server (%i bytes)", | |||
contentLength); | contentLength); | |||
return 500; | return 500; | |||
} | } | |||
NGBufferedDescriptor_flush(toApp); | NGBufferedDescriptor_flush(toApp); | |||
} | } | |||
else { | else { | |||
if (HEAVY_LOG) { | if (HEAVY_LOG) { | |||
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, | |||
"no content in request to transfer"); | "no content in request to transfer"); | |||
} | } | |||
} | } | |||
/* read response line */ | /* read response line */ | |||
if (!NGScanResponseLine(toApp, NULL, &statusCode, NULL)) { | if (!NGScanResponseLine(toApp, NULL, &statusCode, NULL)) { | |||
if (toApp) { | if (toApp) { | |||
NGBufferedDescriptor_free(toApp); | NGBufferedDescriptor_free(toApp); | |||
toApp = NULL; | toApp = NULL; | |||
} | } | |||
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, | |||
"error during reading of response line .."); | "error during reading of response line .."); | |||
return 500; | return 500; | |||
} | } | |||
r->status = statusCode; | r->status = statusCode; | |||
r->status_line = NULL; | r->status_line = NULL; | |||
/* process response headers */ | /* process response headers */ | |||
{ | { | |||
apr_table_t *headers = NULL; | apr_table_t *headers = NULL; | |||
if (HEAVY_LOG) | if (HEAVY_LOG) | |||
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, r->server, "scan headers") ; | ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, "scan headers"); | |||
if ((headers = NGScanHeaders(r->pool, toApp)) == NULL) { | if ((headers = NGScanHeaders(r->pool, toApp)) == NULL) { | |||
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, | |||
"error during parsing of response headers .."); | "error during parsing of response headers .."); | |||
} | } | |||
_copyHeadersToRequest(r, headers, &contentLength); | _copyHeadersToRequest(r, headers, &contentLength); | |||
#ifdef AP_VERSION_1 | #ifdef AP_VERSION_1 | |||
ap_send_http_header(r); | ap_send_http_header(r); | |||
#endif | #endif | |||
} | } | |||
/* send response content */ | /* send response content */ | |||
if (!r->header_only) { | if (!r->header_only) { | |||
if (contentLength > 0) { | if (contentLength > 0) { | |||
void *buffer = NULL; | void *buffer = NULL; | |||
if ((buffer = apr_pcalloc(r->pool, contentLength + 1)) == NULL) { | if ((buffer = apr_pcalloc(r->pool, contentLength + 1)) == NULL) { | |||
ap_log_error(__FILE__, __LINE__, APLOG_ERR, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, | |||
"could not allocate response buffer (size=%i)", | "could not allocate response buffer (size=%i)", | |||
contentLength); | contentLength); | |||
} | } | |||
// read whole response | // read whole response | |||
NGBufferedDescriptor_safeRead(toApp, buffer, contentLength); | NGBufferedDescriptor_safeRead(toApp, buffer, contentLength); | |||
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, | |||
"send response (size=%i)", | "send response (size=%i)", | |||
contentLength); | contentLength); | |||
// send response to client | // send response to client | |||
ap_rwrite(buffer, contentLength, r); | ap_rwrite(buffer, contentLength, r); | |||
ap_rflush(r); | ap_rflush(r); | |||
} | } | |||
else if (contentLength == 0) { | else if (contentLength == 0) { | |||
// no content length header, read until EOF | // no content length header, read until EOF | |||
unsigned char buffer[4096]; | unsigned char buffer[4096]; | |||
int result = 0; | int result = 0; | |||
skipping to change at line 753 | skipping to change at line 757 | |||
while ((result = NGBufferedDescriptor_read(toApp, | while ((result = NGBufferedDescriptor_read(toApp, | |||
buffer, | buffer, | |||
sizeof(buffer)) | sizeof(buffer)) | |||
> 0)) { | > 0)) { | |||
ap_rwrite(buffer, result, r); | ap_rwrite(buffer, result, r); | |||
ap_rflush(r); | ap_rflush(r); | |||
writeCount += result; | writeCount += result; | |||
} | } | |||
if (HEAVY_LOG && (writeCount > 0)) { | if (HEAVY_LOG && (writeCount > 0)) { | |||
ap_log_error(__FILE__, __LINE__, APLOG_INFO, 0, r->server, | ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, | |||
"write %i bytes (without content-length header)", | "write %i bytes (without content-length header)", | |||
writeCount); | writeCount); | |||
} | } | |||
} | } | |||
} | } | |||
// close connection to app | // close connection to app | |||
if (toApp) { | if (toApp) { | |||
NGBufferedDescriptor_free(toApp); | NGBufferedDescriptor_free(toApp); | |||
toApp = NULL; | toApp = NULL; | |||
End of changes. 31 change blocks. | ||||
30 lines changed or deleted | 34 lines changed or added |