You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Ian Kallen <sp...@salon.com> on 1999/06/28 20:37:51 UTC

testing modules, setting headers and PHP

Well, I've written to the Apache API via Perl plenty but I've taken a
stab at cachebusting via a regular old module <gulp., my first>.   I'm
curious if there's a standard set of abuse that I should subject a
server built with an experimental module to.  In my initial tests I
noticed that PHP seems to take over header setting (my module's Expires
and cache control headers seem to go away) but admittedly, I'm not
really conversant enough  with how the handling and tables do their
thing.

Any ideas on how to set these headers without PHP interfering and
general testbenching experimental modules welcome. My sorry ass code
follows,  thanks!

#include "httpd.h"
#include "http_config.h"

module cachekow_module;

static int mtime_header_fixup(request_rec *r)
{
   /* Don't add Expires headers to errors */
   if (ap_is_HTTP_ERROR(r->status))       
            return DECLINED;
   /* Say no to subrequests */
   if (r->main != NULL)        
            return DECLINED;
   /* Danger Will Robinson: no content type, no play */
   if (r->content_type == NULL)
            return DECLINED;
   /* We're sending HTML? */
   if (strcmp(r->content_type, "text/html") == 0) {   
      /* Send proxy cache control directives appropriate to the client
*/
      if (r->proto_num == HTTP_VERSION(1,0)) {
         ap_table_setn(r->headers_out, "Pragma","no-cache");
      }
      if (r->proto_num == HTTP_VERSION(1,1)) {
         ap_table_setn(r->headers_out, "Cache-Control","no-cache,
must-revalidate");
      }
      /* Send an Expires header */
      ap_table_setn(r->headers_out, "Expires",
ap_gm_timestr_822(r->pool, r->request_time));
      /* Put a bogus last modified value in the table */
      ap_update_mtime(r, r->request_time);
      ap_set_last_modified(r);
   }
   return DECLINED;
}

module MODULE_VAR_EXPORT cachekow_module =
{
    STANDARD_MODULE_STUFF,
    NULL,                       /* initializer */
    NULL,                       /* dir config creater */
    NULL,                       /* dir merger --- default is to override
*/
    NULL,                       /* server config */
    NULL,                       /* merge server configs */
    NULL,                       /* command table */
    NULL,                       /* handlers */
    NULL,                       /* filename translation */
    NULL,                       /* check_user_id */
    NULL,                       /* check auth */
    NULL,                       /* check access */
    NULL,                       /* type_checker */
    mtime_header_fixup,         /* fixups */
    NULL,                       /* logger */
    NULL,                       /* header parser */
    NULL,                       /* child_init */
    NULL,                       /* child_exit */
    NULL                        /* post read-request */
};







--
Salon Internet 				http://www.salon.com/
  HTTP mechanic, Perl diver, Mebwaster, Some of the above
	    Ian Kallen <id...@salon.com>

Re: testing modules, setting headers and PHP

Posted by Rodent of Unusual Size <Ke...@Golux.Com>.
Rasmus Lerdorf wrote:
> 
> I think the problem is that mod_php is called during the 'handlers'
> phase and because it generates actual content it forces out the
> headers.  If you were to pick a request phase that occurs prior to
> mod_php being called and inject your headers into the headers table,
> then they will be there when mod_php eventually calls
> ap_http_send_header().

Actually, the fixup phase runs before the content-delivery phase,
so this doesn't seem a likely cause.  Your (Ian's) hook will have
run before PHP's content hook does.

One possibility is that the document is being handled under
error conditions; r->headers_out is ignored in that case, and
only r->err_headers_out is retained.  Ian, try putting your
response fields into the r->err_headers_out table instead and
see what happens.
-- 
#ken    P-)}

Ken Coar                    <http://Web.Golux.Com/coar/>
Apache Software Foundation  <http://www.apache.org/>
"Apache Server for Dummies" <http://Web.Golux.Com/coar/ASFD/>

Re: testing modules, setting headers and PHP

Posted by Rasmus Lerdorf <ra...@raleigh.ibm.com>.
> module MODULE_VAR_EXPORT cachekow_module =
> {
>     STANDARD_MODULE_STUFF,
>     NULL,                       /* initializer */
>     NULL,                       /* dir config creater */
>     NULL,                       /* dir merger --- default is to override
> */
>     NULL,                       /* server config */
>     NULL,                       /* merge server configs */
>     NULL,                       /* command table */
>     NULL,                       /* handlers */
>     NULL,                       /* filename translation */
>     NULL,                       /* check_user_id */
>     NULL,                       /* check auth */
>     NULL,                       /* check access */
>     NULL,                       /* type_checker */
>     mtime_header_fixup,         /* fixups */
>     NULL,                       /* logger */
>     NULL,                       /* header parser */
>     NULL,                       /* child_init */
>     NULL,                       /* child_exit */
>     NULL                        /* post read-request */
> };

I think the problem is that mod_php is called during the 'handlers' phase
and because it generates actual content it forces out the headers.  If you
were to pick a request phase that occurs prior to mod_php being called and
inject your headers into the headers table, then they will be there when
mod_php eventually calls ap_http_send_header().

-Rasmus