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 Zeus Capricorn <ze...@gmail.com> on 2007/06/06 08:07:56 UTC

nothing in the r->headers_out?

Hi,all
      I was reading Nick's book these days,and i got in trouble in chapter 5
.

      it does print the r->headers_in(Host,Accept,etc.),but nothing
else.Where is the r->headers_out and r->subprocess_env?

      Thanks in advance.

The code goes here:
static int printitem(void *rec, const char *key, const char *value)
{
/* rec is a user data pointer.  We'll pass the request_rec in it. */
request_rec *r = rec;
ap_rprintf(r, "<tr><th scope=\"row\">%s</th><td>%s</td></tr>\n",
ap_escape_html(r->pool, key),
ap_escape_html(r->pool, value));
/* Zero would stop iterating; any other return value continues */
return 1;
}
static void printtable(request_rec *r, apr_table_t *t,
const char *caption, const char *keyhead,
const char *valhead)
{
/* Print a table header */
ap_rprintf(r, "<table><caption>%s</caption><thead>"
                 "<tr><th scope=\"col\">%s</th><th scope=\"col\">%s"
                 "</th></tr></thead><tbody>", caption, keyhead, valhead);
/* Print the data: apr_table_do iterates over entries with
* our callback
*/
apr_table_do(printitem, r, t, NULL);
/* Finish the table */
ap_rputs("</tbody></table>\n", r);
}
static int helloworld_handler(request_rec *r)
{
if (!r->handler || (strcmp(r->handler, "helloworld") != 0)) {
return DECLINED ;
}
if (r->method_number != M_GET) {
return HTTP_METHOD_NOT_ALLOWED;
}
ap_set_content_type(r, "text/html;charset=ascii");
ap_rputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n"
    "<html><head><title>Apache HelloWorld Module</title></head>"
    "<body><h1>Hello World!</h1>"
    "<p>This is the Apache HelloWorld module!</p>", r);
/* Print the tables */
printtable(r, r->headers_in, "Request Headers", "Header", "Value");
printtable(r, r->headers_out, "Response Headers", "Header", "Value");
printtable(r, r->subprocess_env, "Environment", "Variable", "Value");
ap_rputs("</body></html>", r);
return OK;
}

Re: nothing in the r->headers_out?

Posted by Graham Dumpleton <gr...@gmail.com>.
On 07/06/07, Zeus Capricorn <ze...@gmail.com> wrote:
> Thank you for your reply.
>
> But when i use telnet to get the page, httpd server does response some
> response headers(e-tag,etc.),and these headers are not in the page source.
>
> Does httpd server append the response headers after the handler phrase ?

Yes, there are some headers which are added by the HTTP_HEADER output
filters for HTTP requests. See ap_http_header_filter() in
modules/http/http_filters.c file.

I think it adds them to headers_out to prepare them for writing, so
one way to force it to be done is to write a separate blank line and
flush it, so that headers are created and written, before actually
creating your content which shows all the headers in headers_out.

Graham

Re: nothing in the r->headers_out?

Posted by Zeus Capricorn <ze...@gmail.com>.
Thank you for your reply.

But when i use telnet to get the page, httpd server does response some
response headers(e-tag,etc.),and these headers are not in the page source.

Does httpd server append the response headers after the handler phrase ?

Re: nothing in the r->headers_out?

Posted by Vincent Bray <no...@gmail.com>.
On 06/06/07, Zeus Capricorn <ze...@gmail.com> wrote:
> Hi,all
>       I was reading Nick's book

Isn't it great?

>       it does print the r->headers_in(Host,Accept,etc.),but nothing
> else.Where is the r->headers_out and r->subprocess_env?

AFAICT, because this module doesn't invoke anything from util_script,
the normal cgi environment variables don't exist. mod_cgi(d) &
mod_includes call on those functions to populate the environment
table. See this file in the httpd source /server/util_script.c

So, to see something in the env var table, either call
ap_add_common_vars() or use SetEnv in your config (or both).

I'm less sure about the response headers but it's probably a similar
deal. Try mod_header's Header directive.

-- 
noodl