httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Schaefer <joe+gm...@sunstarsys.com>
Subject Re: cvs commit: httpd-apreq-2/env/t/cgi-bin .cvsignore
Date Fri, 24 Oct 2003 22:07:08 GMT
Randy Kobes <randy@theoryx5.uwinnipeg.ca> writes:

[...]

> >  APREQ_DECLARE(const char *)apreq_env_header_in(void *env,
> >                                                 const char *name)
> >  {
> > -    dCTX;
> > -    char *key = apr_pstrdup(ctx->pool, name);
> > -    char *k, *value=NULL, *http_key, http[] = "HTTP_";
> > +    dP;
> > +    char *key = apr_pstrcat(p, "HTTP_", name, NULL);
> > +    char *k, *value = NULL;
> >      for (k = key; *k; ++k) {
> >          if (*k == '-')
> >              *k = '_';
> > @@ -130,67 +128,63 @@
> >              *k = apr_toupper(*k);
> >      }
> >
> > -    if (!strcmp(key, "CONTENT_TYPE") || !strcmp(key, "CONTENT_LENGTH")) {
> > -        APREQ_ENV_STATUS(apr_env_get(&value, key, ctx->pool), key);
> > -    }
> > -    else {
> > -        http_key = (char *) apr_palloc(ctx->pool, sizeof(http) + strlen(key));
> > -        http_key = strcat(strcpy(http_key, http), key);
> > -        APREQ_ENV_STATUS(apr_env_get(&value, http_key, ctx->pool), http_key);
> > +    if (!strcmp(key, "HTTP_CONTENT_TYPE")
> > +        || !strcmp(key, "HTTP_CONTENT_LENGTH")) {
> > +
> > +        key += 5; /* strlen("HTTP_") */
> >      }
> >
> > +    APREQ_ENV_STATUS(apr_env_get(&value, key, p), key);
> > +
> >      return value;
> >  }
> 
> If I understand this correctly, HTTP_ is being prepended to
> the "name" being passed in ... 

Right, and the resulting pointer (key) is bumped past the "HTTP_" 
part for "HTTP_CONTENT_TYPE" and "HTTP_CONTENT_LENGTH".  The 
advantage being we only do one pool allocation this way (instead of
two).  It should be functionally equivalent to the original.

-- 
Joe Schaefer


Mime
View raw message