Developing custom modules Apache - Http Headers

时间:2018-01-15 18:09:30

标签: c apache http

I'm trying to hook the correct time to send a forward header before mod_proxy acts.

#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "ap_config.h"

static int my_handler(request_rec *r)
{
     if (!r->handler || strcmp(r->handler, "my_handler")) return (DECLINED);

    apr_table_setn(r->headers_in, "key", "hola");
    return OK;
}
static void my_hooks(apr_pool_t *p)
{
    ap_hook_handler(my_handler, NULL, NULL, APR_HOOK_MIDDLE);
}

/* Dispatch list for API hooks */
module AP_MODULE_DECLARE_DATA my_module = {
    STANDARD20_MODULE_STUFF, 
    NULL,                  /* create per-dir    config structures */
    NULL,                  /* merge  per-dir    config structures */
    NULL,                  /* create per-server config structures */
    NULL,                  /* merge  per-server config structures */
    NULL,                  /* table of config file commands       */
    my_hooks  /* register hooks              */
};

And the following config.

<IfModule mod_ssl.c>
        <VirtualHost *:443>
                ServerAdmin webmaster@localhost

            LoadModule my_module modules/mod_forward_headers.so
            AddHandler my_handler .sum

            ErrorLog /var/log/apache2/ssl_engine.log
            CustomLog ${APACHE_LOG_DIR}/SSL_access.log combined
            LogLevel debug

            #   SSL Engine Switch:
            #   Enable/Disable SSL for this virtual host.
            SSLEngine on

            proxyPass ....

            [....]

I tried to hook APR_HOOK_MIDDLE, APR_HOOK_FIRST, and APR_HOOK_LAST and nothing works as expected.

Suggestions?

0 个答案:

没有答案