You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Marco Spinetti <m....@pisa.iol.it> on 2007/09/04 10:52:03 UTC

static page by module

I'm a bit confused how to serve a static page by a module.
I'm using apache 2.2.4: in particular cases I'd like that my module 
replies with a static page (/www/static.html).
Now in these cases my module replies with:

apr_table_set(r->headers_out, "Location", sconf->html);
apr_table_set(r->headers_out, "Content-Location", sconf->html);
apr_table_unset(r->headers_out, "Content-Length");
apr_table_unset(r->headers_out, "Content-Type");
return HTTP_TEMPORARY_REDIRECT;

but in this way the client makes a new request to the page static.html.
I'm like to serve the page immediatly without any other request.
Is it possible?
Best regards

Marco



Re: static page by module

Posted by Marco Spinetti <m....@pisa.iol.it>.
It seems that this is the way:

rv = apr_file_open(&file, sconf->html, APR_READ, APR_UREAD | APR_UWRITE 
| APR_GREAD, r->pool);
if (rv != APR_SUCCESS) {
            .......
}
rv = apr_file_info_get(&finfo, APR_FINFO_MIN, file);
if (rv != APR_SUCCESS) {
            apr_file_close(file);
            ......
}
ap_set_content_type(r, "text/html");
ap_send_fd(file, r, 0, finfo.size, &inviati);                         
apr_file_close(file);
return OK;

Is it correct?
Best regards

Marco

Marco Spinetti ha scritto:
> I'm a bit confused how to serve a static page by a module.
> I'm using apache 2.2.4: in particular cases I'd like that my module 
> replies with a static page (/www/static.html).
> Now in these cases my module replies with:
>
> apr_table_set(r->headers_out, "Location", sconf->html);
> apr_table_set(r->headers_out, "Content-Location", sconf->html);
> apr_table_unset(r->headers_out, "Content-Length");
> apr_table_unset(r->headers_out, "Content-Type");
> return HTTP_TEMPORARY_REDIRECT;
>
> but in this way the client makes a new request to the page static.html.
> I'm like to serve the page immediatly without any other request.
> Is it possible?
> Best regards
>
> Marco
>
>


Re: static page by module

Posted by Tim Bray <Ti...@Sun.COM>.
On Sep 4, 2007, at 1:52 AM, Marco Spinetti wrote:

> I'm a bit confused how to serve a static page by a module.
> I'm using apache 2.2.4: in particular cases I'd like that my module  
> replies with a static page (/www/static.html).
> Now in these cases my module replies with:

I think the easiest thing is to get the map_to_storage hook, then set  
the r->filename, r->canonical_filename, and the r->finfo fields  
(APR_FINFO_MTIME|APR_FINFO_INODE|APR_FINFO_SIZE seem to be enough),  
then return OK and let httpd do it. -Tim