You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by br...@apache.org on 2002/05/10 08:47:13 UTC
cvs commit: httpd-2.0/server core.c protocol.c
brianp 02/05/09 23:47:13
Modified: server core.c protocol.c
Log:
Performance fix: replaced the strcasecmp calls in ap_make_content_type()
with apr_strmatch()
Revision Changes Path
1.174 +3 -0 httpd-2.0/server/core.c
Index: core.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/core.c,v
retrieving revision 1.173
retrieving revision 1.174
diff -u -r1.173 -r1.174
--- core.c 30 Apr 2002 20:12:26 -0000 1.173
+++ core.c 10 May 2002 06:47:13 -0000 1.174
@@ -3851,9 +3851,12 @@
return APR_SUCCESS;
}
+AP_DECLARE(void) ap_setup_make_content_type(apr_pool_t *pool);
+
static int core_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
ap_set_version(pconf);
+ ap_setup_make_content_type(pconf);
return OK;
}
1.99 +32 -8 httpd-2.0/server/protocol.c
Index: protocol.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/protocol.c,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -r1.98 -r1.99
--- protocol.c 6 May 2002 09:11:50 -0000 1.98
+++ protocol.c 10 May 2002 06:47:13 -0000 1.99
@@ -68,6 +68,7 @@
#include "apr_buckets.h"
#include "apr_lib.h"
#include "apr_signal.h"
+#include "apr_strmatch.h"
#define APR_WANT_STDIO /* for sscanf */
#define APR_WANT_STRFUNC
@@ -107,6 +108,30 @@
AP_DECLARE_DATA ap_filter_rec_t *ap_old_write_func = NULL;
+
+/* Patterns to match in ap_make_content_type() */
+static const char *needcset[] = {
+ "text/plain",
+ "text/html",
+ NULL
+};
+static const apr_strmatch_pattern **needcset_patterns;
+static const apr_strmatch_pattern *charset_pattern;
+
+AP_DECLARE(void) ap_setup_make_content_type(apr_pool_t *pool)
+{
+ int i;
+ for (i = 0; needcset[i]; i++) {
+ continue;
+ }
+ needcset_patterns = (const apr_strmatch_pattern **)
+ apr_palloc(pool, (i + 1) * sizeof(apr_strmatch_pattern *));
+ for (i = 0; needcset[i]; i++) {
+ needcset_patterns[i] = apr_strmatch_precompile(pool, needcset[i], 0);
+ }
+ charset_pattern = apr_strmatch_precompile(pool, "charset=", 0);
+}
+
/*
* Builds the content-type that should be sent to the client from the
* content-type specified. The following rules are followed:
@@ -117,14 +142,11 @@
*/
AP_DECLARE(const char *)ap_make_content_type(request_rec *r, const char *type)
{
- static const char *needcset[] = {
- "text/plain",
- "text/html",
- NULL };
- const char **pcset;
+ const apr_strmatch_pattern **pcset;
core_dir_config *conf =
(core_dir_config *)ap_get_module_config(r->per_dir_config,
&core_module);
+ apr_size_t type_len;
if (!type) {
type = ap_default_type(r);
@@ -134,7 +156,9 @@
return type;
}
- if (ap_strcasestr(type, "charset=") != NULL) {
+ type_len = strlen(type);
+
+ if (apr_strmatch(charset_pattern, type, type_len) != NULL) {
/* already has parameter, do nothing */
/* XXX we don't check the validity */
;
@@ -143,8 +167,8 @@
/* see if it makes sense to add the charset. At present,
* we only add it if the Content-type is one of needcset[]
*/
- for (pcset = needcset; *pcset ; pcset++) {
- if (ap_strcasestr(type, *pcset) != NULL) {
+ for (pcset = needcset_patterns; *pcset ; pcset++) {
+ if (apr_strmatch(*pcset, type, type_len) != NULL) {
type = apr_pstrcat(r->pool, type, "; charset=",
conf->add_default_charset_name, NULL);
break;
Re: cvs commit: httpd-2.0/server core.c protocol.c
Posted by Brian Pane <br...@cnet.com>.
Jeff Trawick wrote:
>>+AP_DECLARE(void) ap_setup_make_content_type(apr_pool_t *pool);
>>
>
>What's up with this? This has to go in a header file included by both
>core.c and protocol.c.
>
It's fixed now (I moved the declaration to http_protocol.h and
wrapped it in #ifdef CORE_PRIVATE)
--Brian
Re: cvs commit: httpd-2.0/server core.c protocol.c
Posted by Jeff Trawick <tr...@attglobal.net>.
brianp@apache.org writes:
> brianp 02/05/09 23:47:13
>
> Modified: server core.c protocol.c
> Log:
> Performance fix: replaced the strcasecmp calls in ap_make_content_type()
> with apr_strmatch()
>
> Index: core.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/server/core.c,v
> retrieving revision 1.173
> retrieving revision 1.174
> diff -u -r1.173 -r1.174
> --- core.c 30 Apr 2002 20:12:26 -0000 1.173
> +++ core.c 10 May 2002 06:47:13 -0000 1.174
> @@ -3851,9 +3851,12 @@
> return APR_SUCCESS;
> }
>
> +AP_DECLARE(void) ap_setup_make_content_type(apr_pool_t *pool);
What's up with this? This has to go in a header file included by both
core.c and protocol.c.
--
Jeff Trawick | trawick@attglobal.net
Born in Roswell... married an alien...
Re: cvs commit: httpd-2.0/server core.c protocol.c
Posted by Jeff Trawick <tr...@attglobal.net>.
brianp@apache.org writes:
> brianp 02/05/09 23:47:13
>
> Modified: server core.c protocol.c
> Log:
> Performance fix: replaced the strcasecmp calls in ap_make_content_type()
> with apr_strmatch()
>
> Index: core.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/server/core.c,v
> retrieving revision 1.173
> retrieving revision 1.174
> diff -u -r1.173 -r1.174
> --- core.c 30 Apr 2002 20:12:26 -0000 1.173
> +++ core.c 10 May 2002 06:47:13 -0000 1.174
> @@ -3851,9 +3851,12 @@
> return APR_SUCCESS;
> }
>
> +AP_DECLARE(void) ap_setup_make_content_type(apr_pool_t *pool);
What's up with this? This has to go in a header file included by both
core.c and protocol.c.
--
Jeff Trawick | trawick@attglobal.net
Born in Roswell... married an alien...