1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-07 04:02:58 +03:00

First commit to introduce accessor function to set r->content_type..

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@94027 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bill Stoddard
2002-03-20 01:58:47 +00:00
parent 32fe8d097f
commit 470edb9dd8
19 changed files with 63 additions and 52 deletions

View File

@@ -345,7 +345,7 @@ static int dav_error_response(request_rec *r, int status, const char *body)
/* ### I really don't think this is needed; gotta test */ /* ### I really don't think this is needed; gotta test */
r->status_line = ap_get_status_line(status); r->status_line = ap_get_status_line(status);
r->content_type = "text/html"; ap_rset_content_type("text/html", r);
/* since we're returning DONE, ensure the request body is consumed. */ /* since we're returning DONE, ensure the request body is consumed. */
(void) ap_discard_request_body(r); (void) ap_discard_request_body(r);
@@ -382,7 +382,7 @@ static int dav_error_response_tag(request_rec *r,
/* ### I really don't think this is needed; gotta test */ /* ### I really don't think this is needed; gotta test */
r->status_line = ap_get_status_line(err->status); r->status_line = ap_get_status_line(err->status);
r->content_type = DAV_XML_CONTENT_TYPE; ap_rset_content_type(DAV_XML_CONTENT_TYPE, r);
/* since we're returning DONE, ensure the request body is consumed. */ /* since we're returning DONE, ensure the request body is consumed. */
(void) ap_discard_request_body(r); (void) ap_discard_request_body(r);
@@ -455,7 +455,7 @@ static void dav_send_multistatus(request_rec *r, int status,
{ {
/* Set the correct status and Content-Type */ /* Set the correct status and Content-Type */
r->status = status; r->status = status;
r->content_type = DAV_XML_CONTENT_TYPE; ap_rset_content_type(DAV_XML_CONTENT_TYPE, r);
/* Send the headers and actual multistatus response now... */ /* Send the headers and actual multistatus response now... */
ap_rputs(DAV_XML_HEADER DEBUG_CR ap_rputs(DAV_XML_HEADER DEBUG_CR
@@ -1693,7 +1693,7 @@ static int dav_method_options(request_rec *r)
/* send the options response */ /* send the options response */
r->status = HTTP_OK; r->status = HTTP_OK;
r->content_type = DAV_XML_CONTENT_TYPE; ap_rset_content_type(DAV_XML_CONTENT_TYPE, r);
/* send the headers and response body */ /* send the headers and response body */
ap_rputs(DAV_XML_HEADER DEBUG_CR ap_rputs(DAV_XML_HEADER DEBUG_CR
@@ -2920,7 +2920,7 @@ static int dav_method_lock(request_rec *r)
(*locks_hooks->close_lockdb)(lockdb); (*locks_hooks->close_lockdb)(lockdb);
r->status = HTTP_OK; r->status = HTTP_OK;
r->content_type = DAV_XML_CONTENT_TYPE; ap_rset_content_type(DAV_XML_CONTENT_TYPE, r);
ap_rputs(DAV_XML_HEADER DEBUG_CR "<D:prop xmlns:D=\"DAV:\">" DEBUG_CR, r); ap_rputs(DAV_XML_HEADER DEBUG_CR "<D:prop xmlns:D=\"DAV:\">" DEBUG_CR, r);
if (lock == NULL) if (lock == NULL)
@@ -3878,7 +3878,7 @@ static int dav_method_report(request_rec *r)
/* set up defaults for the report response */ /* set up defaults for the report response */
r->status = HTTP_OK; r->status = HTTP_OK;
r->content_type = DAV_XML_CONTENT_TYPE; ap_rset_content_type(DAV_XML_CONTENT_TYPE, r);
/* run report hook */ /* run report hook */
if ((err = (*vsn_hooks->deliver_report)(r, resource, doc, if ((err = (*vsn_hooks->deliver_report)(r, resource, doc,
@@ -4125,7 +4125,7 @@ static int dav_method_merge(request_rec *r)
is going to do something different (i.e. an error), then it must is going to do something different (i.e. an error), then it must
return a dav_error, and we'll reset these values properly. */ return a dav_error, and we'll reset these values properly. */
r->status = HTTP_OK; r->status = HTTP_OK;
r->content_type = "text/xml"; ap_rset_content_type("text/xml", r);
/* ### should we do any preliminary response generation? probably not, /* ### should we do any preliminary response generation? probably not,
### because we may have an error, thus demanding something else in ### because we may have an error, thus demanding something else in

View File

@@ -237,7 +237,7 @@ apr_status_t cache_read_entity_headers(cache_handle_t *h, request_rec *r)
return rv; return rv;
} }
r->content_type = apr_pstrdup(r->pool, info->content_type); ap_rset_content_type(apr_pstrdup(r->pool, info->content_type), r);
r->filename = apr_pstrdup(r->pool, info->filename ); r->filename = apr_pstrdup(r->pool, info->filename );
return APR_SUCCESS; return APR_SUCCESS;

View File

@@ -552,7 +552,7 @@ static int x_handler(request_rec *r)
* We also need to start a timer so the server can know if the connexion * We also need to start a timer so the server can know if the connexion
* is broken. * is broken.
*/ */
r->content_type = "text/html"; ap_rset_content_type("text/html", r);
/* /*
* If we're only supposed to send header information (HEAD request), we're * If we're only supposed to send header information (HEAD request), we're
* already there. * already there.

View File

@@ -3453,7 +3453,7 @@ static int include_fixup(request_rec *r)
if (r->handler && (strcmp(r->handler, "server-parsed") == 0)) if (r->handler && (strcmp(r->handler, "server-parsed") == 0))
{ {
if (!r->content_type || !*r->content_type) { if (!r->content_type || !*r->content_type) {
r->content_type = "text/html"; ap_rset_content_type("text/html", r);
} }
r->handler = "default-handler"; r->handler = "default-handler";
} }

View File

@@ -1895,9 +1895,9 @@ static int index_directory(request_rec *r,
} }
#if APR_HAS_UNICODE_FS #if APR_HAS_UNICODE_FS
r->content_type = "text/html;charset=utf-8"; ap_rset_content_type("text/html;charset=utf-8", r);
#else #else
r->content_type = "text/html"; ap_rset_content_type("text/html", r);
#endif #endif
if (autoindex_opts & TRACK_MODIFIED) { if (autoindex_opts & TRACK_MODIFIED) {
ap_update_mtime(r, r->finfo.mtime); ap_update_mtime(r, r->finfo.mtime);

View File

@@ -788,7 +788,7 @@ static int include_cgi(char *s, request_rec *r, ap_filter_t *next,
* typing rules would have called it something else. * typing rules would have called it something else.
*/ */
rr->content_type = CGI_MAGIC_TYPE; ap_rset_content_type(CGI_MAGIC_TYPE, rr);
/* Run it. */ /* Run it. */

View File

@@ -1216,8 +1216,7 @@ static int include_cgi(char *s, request_rec *r, ap_filter_t *next,
/* Force sub_req to be treated as a CGI request, even if ordinary /* Force sub_req to be treated as a CGI request, even if ordinary
* typing rules would have called it something else. * typing rules would have called it something else.
*/ */
ap_rset_content_type(CGI_MAGIC_TYPE, rr);
rr->content_type = CGI_MAGIC_TYPE;
/* Run it. */ /* Run it. */

View File

@@ -377,7 +377,7 @@ static int display_info(request_rec *r)
if (r->method_number != M_GET) if (r->method_number != M_GET)
return DECLINED; return DECLINED;
r->content_type = "text/html"; ap_rset_content_type("text/html", r);
if (r->header_only) { if (r->header_only) {
return 0; return 0;
} }

View File

@@ -283,7 +283,7 @@ static int status_handler(request_rec *r)
if (r->method_number != M_GET) if (r->method_number != M_GET)
return DECLINED; return DECLINED;
r->content_type = "text/html"; ap_rset_content_type("text/html", r);
/* /*
* Simple table-driven form data set parser that lets you alter the header * Simple table-driven form data set parser that lets you alter the header
@@ -312,7 +312,7 @@ static int status_handler(request_rec *r)
no_table_report = 1; no_table_report = 1;
break; break;
case STAT_OPT_AUTO: case STAT_OPT_AUTO:
r->content_type = "text/plain"; ap_rset_content_type("text/plain", r);
short_report = 1; short_report = 1;
break; break;
} }

View File

@@ -1145,7 +1145,7 @@ AP_DECLARE_NONSTD(int) ap_send_http_trace(request_rec *r)
return rv; return rv;
} }
r->content_type = "message/http"; ap_rset_content_type("message/http", r);
/* Now we recreate the request, and echo it back */ /* Now we recreate the request, and echo it back */
@@ -1253,6 +1253,17 @@ static void fixup_vary(request_rec *r)
apr_array_pstrcat(r->pool, varies, ',')); apr_array_pstrcat(r->pool, varies, ','));
} }
} }
AP_DECLARE(void) ap_rset_content_type(char *ct, request_rec *r)
{
r->content_type = ct;
/* Insert filters requested by the AddOutputFiltersByType
* configuration directive. Content-type filters must be
* inserted after the content handlers have run because
* only then, do we reliably know the content-type.
*/
ap_add_output_filters_by_type(r);
}
typedef struct header_filter_ctx { typedef struct header_filter_ctx {
int headers_sent; int headers_sent;
@@ -2039,7 +2050,7 @@ AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error)
r->content_languages = NULL; r->content_languages = NULL;
r->content_encoding = NULL; r->content_encoding = NULL;
r->clength = 0; r->clength = 0;
r->content_type = "text/html; charset=iso-8859-1"; ap_rset_content_type("text/html; charset=iso-8859-1", r);
if ((status == HTTP_METHOD_NOT_ALLOWED) if ((status == HTTP_METHOD_NOT_ALLOWED)
|| (status == HTTP_NOT_IMPLEMENTED)) { || (status == HTTP_NOT_IMPLEMENTED)) {
@@ -2593,10 +2604,10 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_byterange_filter(ap_filter_t *f,
if (num_ranges > 1) { if (num_ranges > 1) {
ctx->orig_ct = r->content_type; ctx->orig_ct = r->content_type;
r->content_type = apr_pstrcat(r->pool, "multipart", ap_rset_content_type(apr_pstrcat(r->pool, "multipart",
use_range_x(r) ? "/x-" : "/", use_range_x(r) ? "/x-" : "/",
"byteranges; boundary=", "byteranges; boundary=",
r->boundary, NULL); r->boundary, NULL), r);
} }
/* create a brigade in case we never call ap_save_brigade() */ /* create a brigade in case we never call ap_save_brigade() */

View File

@@ -386,7 +386,7 @@ AP_DECLARE(void) ap_internal_fast_redirect(request_rec *rr, request_rec *r)
r->args = rr->args; r->args = rr->args;
r->finfo = rr->finfo; r->finfo = rr->finfo;
r->handler = rr->handler; r->handler = rr->handler;
r->content_type = rr->content_type; ap_rset_content_type(rr->content_type, r);
r->content_encoding = rr->content_encoding; r->content_encoding = rr->content_encoding;
r->content_languages = rr->content_languages; r->content_languages = rr->content_languages;
r->per_dir_config = rr->per_dir_config; r->per_dir_config = rr->per_dir_config;
@@ -428,7 +428,7 @@ AP_DECLARE(void) ap_internal_redirect_handler(const char *new_uri, request_rec *
int access_status; int access_status;
request_rec *new = internal_internal_redirect(new_uri, r); request_rec *new = internal_internal_redirect(new_uri, r);
if (r->handler) if (r->handler)
new->content_type = r->content_type; ap_rset_content_type(r->content_type, new);
access_status = ap_process_request_internal(new); access_status = ap_process_request_internal(new);
if (access_status == OK) { if (access_status == OK) {
if ((access_status = ap_invoke_handler(new)) != 0) { if ((access_status = ap_invoke_handler(new)) != 0) {

View File

@@ -76,7 +76,7 @@
#include "http_config.h" #include "http_config.h"
#include "http_log.h" #include "http_log.h"
#include "http_request.h" #include "http_request.h"
#include "http_protocol.h"
/* XXXX - fix me / EBCDIC /* XXXX - fix me / EBCDIC
* there was a cludge here which would use its * there was a cludge here which would use its
@@ -744,7 +744,7 @@ static int find_ct(request_rec *r)
int found_metadata = 0; int found_metadata = 0;
if (r->finfo.filetype == APR_DIR) { if (r->finfo.filetype == APR_DIR) {
r->content_type = DIR_MAGIC_TYPE; ap_rset_content_type(DIR_MAGIC_TYPE, r);
return OK; return OK;
} }
@@ -793,7 +793,7 @@ static int find_ct(request_rec *r)
if (exinfo == NULL || !exinfo->forced_type) { if (exinfo == NULL || !exinfo->forced_type) {
if ((type = apr_hash_get(mime_type_extensions, ext, if ((type = apr_hash_get(mime_type_extensions, ext,
APR_HASH_KEY_STRING)) != NULL) { APR_HASH_KEY_STRING)) != NULL) {
r->content_type = type; ap_rset_content_type((char*) type, r);
found = 1; found = 1;
} }
} }
@@ -801,7 +801,7 @@ static int find_ct(request_rec *r)
if (exinfo != NULL) { if (exinfo != NULL) {
if (exinfo->forced_type) { if (exinfo->forced_type) {
r->content_type = exinfo->forced_type; ap_rset_content_type(exinfo->forced_type, r);
found = 1; found = 1;
} }
@@ -885,29 +885,29 @@ static int find_ct(request_rec *r)
if ((ctp = analyze_ct(r, r->content_type))) { if ((ctp = analyze_ct(r, r->content_type))) {
param *pp = ctp->param; param *pp = ctp->param;
r->content_type = apr_pstrcat(r->pool, ctp->type, "/", ap_rset_content_type(apr_pstrcat(r->pool, ctp->type, "/",
ctp->subtype, NULL); ctp->subtype, NULL), r);
while (pp != NULL) { while (pp != NULL) {
if (charset && !strcmp(pp->attr, "charset")) { if (charset && !strcmp(pp->attr, "charset")) {
if (!override) { if (!override) {
r->content_type = apr_pstrcat(r->pool, r->content_type, ap_rset_content_type(apr_pstrcat(r->pool, r->content_type,
"; charset=", charset, "; charset=", charset,
NULL); NULL), r);
override = 1; override = 1;
} }
} }
else { else {
r->content_type = apr_pstrcat(r->pool, r->content_type, ap_rset_content_type(apr_pstrcat(r->pool, r->content_type,
"; ", pp->attr, "; ", pp->attr,
"=", pp->val, "=", pp->val,
NULL); NULL), r);
} }
pp = pp->next; pp = pp->next;
} }
if (charset && !override) { if (charset && !override) {
r->content_type = apr_pstrcat(r->pool, r->content_type, ap_rset_content_type(apr_pstrcat(r->pool, r->content_type,
"; charset=", charset, "; charset=", charset,
NULL); NULL), r);
} }
} }
} }

View File

@@ -521,7 +521,7 @@ static int imap_reply(request_rec *r, char *redirect)
static void menu_header(request_rec *r, char *menu) static void menu_header(request_rec *r, char *menu)
{ {
r->content_type = "text/html"; ap_rset_content_type("text/html", r);
ap_rvputs(r, DOCTYPE_HTML_3_2, "<html><head>\n<title>Menu for ", r->uri, ap_rvputs(r, DOCTYPE_HTML_3_2, "<html><head>\n<title>Menu for ", r->uri,
"</title>\n</head><body>\n", NULL); "</title>\n</head><body>\n", NULL);

View File

@@ -1115,7 +1115,7 @@ static int read_types_multi(negotiation_state *neg)
* might be doing. * might be doing.
*/ */
if (sub_req->handler && !sub_req->content_type) { if (sub_req->handler && !sub_req->content_type) {
sub_req->content_type = CGI_MAGIC_TYPE; ap_rset_content_type(CGI_MAGIC_TYPE, sub_req);
} }
/* /*

View File

@@ -1311,7 +1311,7 @@ static int hook_mimetype(request_rec *r)
else { else {
rewritelog(r, 1, "force filename %s to have MIME-type '%s'", rewritelog(r, 1, "force filename %s to have MIME-type '%s'",
r->filename, t); r->filename, t);
r->content_type = t; ap_rset_content_type(t, r);
return OK; return OK;
} }
} }
@@ -1959,7 +1959,7 @@ static int apply_rewrite_rule(request_rec *r, rewriterule_entry *p,
*/ */
rewritelog(r, 1, "[per-dir %s] force %s to have MIME-type " rewritelog(r, 1, "[per-dir %s] force %s to have MIME-type "
"'%s'", perdir, r->filename, p->forced_mimetype); "'%s'", perdir, r->filename, p->forced_mimetype);
r->content_type = p->forced_mimetype; ap_rset_content_type(p->forced_mimetype, r);
} }
} }
return 2; return 2;

View File

@@ -165,6 +165,7 @@
#include "util_script.h" #include "util_script.h"
#include "http_log.h" #include "http_log.h"
#include "http_request.h" #include "http_request.h"
#include "http_protocol.h"
#include "apr_lib.h" #include "apr_lib.h"
#define DIR_CMD_PERMS OR_INDEXES #define DIR_CMD_PERMS OR_INDEXES
@@ -292,7 +293,7 @@ static int scan_meta_file(request_rec *r, apr_file_t *f)
tmp = apr_pstrdup(r->pool, l); tmp = apr_pstrdup(r->pool, l);
ap_content_type_tolower(tmp); ap_content_type_tolower(tmp);
r->content_type = tmp; ap_rset_content_type(tmp, r);
} }
else if (!strcasecmp(w, "Status")) { else if (!strcasecmp(w, "Status")) {
sscanf(l, "%d", &r->status); sscanf(l, "%d", &r->status);

View File

@@ -833,7 +833,7 @@ static int magic_rsl_to_request(request_rec *r)
/* XXX: this could be done at config time I'm sure... but I'm /* XXX: this could be done at config time I'm sure... but I'm
* confused by all this magic_rsl stuff. -djg */ * confused by all this magic_rsl stuff. -djg */
ap_content_type_tolower(tmp); ap_content_type_tolower(tmp);
r->content_type = tmp; ap_rset_content_type(tmp, r);
} }
if (state == rsl_encoding) { if (state == rsl_encoding) {
char *tmp; char *tmp;
@@ -2369,7 +2369,7 @@ static int revision_suffix(request_rec *r)
/* extract content type/encoding/language from sub-request */ /* extract content type/encoding/language from sub-request */
if (sub->content_type) { if (sub->content_type) {
r->content_type = apr_pstrdup(r->pool, sub->content_type); ap_rset_content_type(apr_pstrdup(r->pool, sub->content_type), r);
#if MIME_MAGIC_DEBUG #if MIME_MAGIC_DEBUG
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, 0, r, ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, 0, r,
MODNAME ": subrequest %s got %s", MODNAME ": subrequest %s got %s",

View File

@@ -1710,7 +1710,7 @@ int ap_proxy_ftp_handler(request_rec *r, proxy_server_conf *conf,
/* set content-type */ /* set content-type */
if (dirlisting) { if (dirlisting) {
r->content_type = "text/html"; ap_rset_content_type("text/html", r);
} }
else { else {
if (r->content_type) { if (r->content_type) {
@@ -1718,7 +1718,7 @@ int ap_proxy_ftp_handler(request_rec *r, proxy_server_conf *conf,
"proxy: FTP: Content-Type set to %s", r->content_type); "proxy: FTP: Content-Type set to %s", r->content_type);
} }
else { else {
r->content_type = ap_default_type(r); ap_rset_content_type(ap_default_type(r), r);
} }
if (xfer_type != 'A' && size != NULL) { if (xfer_type != 'A' && size != NULL) {
/* We "trust" the ftp server to really serve (size) bytes... */ /* We "trust" the ftp server to really serve (size) bytes... */

View File

@@ -701,7 +701,7 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r,
"close"); "close");
ap_proxy_clear_connection(p, r->headers_out); ap_proxy_clear_connection(p, r->headers_out);
if ((buf = apr_table_get(r->headers_out, "Content-Type"))) { if ((buf = apr_table_get(r->headers_out, "Content-Type"))) {
r->content_type = apr_pstrdup(p, buf); ap_rset_content_type(apr_pstrdup(p, buf), r);
} }
ap_proxy_pre_http_request(origin,rp); ap_proxy_pre_http_request(origin,rp);
} }