--- src/mod_fastcgi.c.orig 2005-03-28 06:50:00.000000000 -0600 +++ src/mod_fastcgi.c 2005-04-22 14:25:31.000000000 -0500 @@ -25,6 +25,7 @@ #include "file_descr_funcs.h" #include "network.h" #include "chunk_funcs.h" +#include "file_cache_funcs.h" #include #include @@ -339,6 +340,8 @@ connection *remote_conn; /* dumb pointer */ plugin_data *plugin_data; /* dumb pointer */ + + file_cache_entry *send_response_body; } handler_ctx; @@ -375,6 +378,7 @@ hctx->reconnects = 0; + hctx->send_response_body = NULL; return hctx; } @@ -1293,6 +1297,10 @@ fcgi_proclist_sort_down(srv, hctx->host, hctx->proc); } + if (hctx->send_response_body != NULL) { + file_cache_release_entry(srv, hctx->send_response_body); + hctx->send_response_body = NULL; + } handler_ctx_free(hctx); con->plugin_ctx[p->id] = NULL; @@ -2116,7 +2124,38 @@ con->file_started = 1; if (blen) { - http_chunk_append_mem(srv, con, c, blen + 1); + + /* check to see if X-send-response-body was set */ + + data_string *path_override = (data_string *) array_get_element(con->response.headers, "X-send-response-body"); + if (path_override != NULL) { + + /* attempt to serve the specified file as the response body */ + + file_cache_entry *fce = NULL; + file_cache_add_entry(srv, con, path_override->value, &fce); + if (fce == NULL) { + + /* an error occurred, so fall back on regular content */ + + buffer_copy_string(path_override->value, "failed"); + path_override = NULL; + } else { + + /* replace regular content with file */ + + hctx->send_response_body = fce; + http_chunk_append_file(srv, con, fce, 0, fce->st.st_size); + buffer_copy_string(path_override->value, "used"); + } + } + + /* if file was not sent, use regular content */ + + if (path_override == NULL) { + http_chunk_append_mem(srv, con, c, blen + 1); + } + joblist_append(srv, con); #if 0 log_error_write(srv, __FILE__, __LINE__, "sd", "body-len", blen);