Welcome! Log In Create A New Profile

Advanced

[nginx] problem with a sample module

Jérôme Loyet
June 01, 2010 02:38AM
Hi,

I'm writing a very simple module which add a header.

In the postconfigure function, I backup up ngx_http_top_header_filter
and set my own filter instead.

static ngx_int_t
ngx_http_xtoken_init(ngx_conf_t *cf)
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_xtoken_clear_cookie_handler;
return NGX_OK;
}

But the function ngx_http_xtoken_filter seems to be never called.

The module is compile with --add-module=/path/to/module

do you have any clue of what I did wrong ?

Thx
++ jerome

Here is my complete source code:
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>

static ngx_int_t ngx_http_xtoken_init(ngx_conf_t *cf);
static ngx_int_t ngx_http_xtoken_filter(ngx_http_request_t *r);

static ngx_http_module_t ngx_http_xtoken_module_ctx = {
NULL, /* preconfiguration */
ngx_http_xtoken_init, /* postconfiguration */

NULL, /* create main configuration */
NULL, /* init main configuration */

NULL, /* create server configuration */
NULL, /* merge server configuration */

NULL, /* create location configuration */
NULL /* merge location configuration */
};


ngx_module_t ngx_http_xtoken_module = {
NGX_MODULE_V1,
&ngx_http_xtoken_module_ctx, /* module context */
NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
NULL, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
NULL, /* exit master */
NGX_MODULE_V1_PADDING
};

static ngx_http_output_header_filter_pt ngx_http_next_header_filter;


static ngx_int_t
ngx_http_xtoken_init(ngx_conf_t *cf)
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_xtoken_clear_cookie_handler;
return NGX_OK;
}

static ngx_int_t
ngx_http_xtoken_filter(ngx_http_request_t *r)
{
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "[xtoken] enter filter");
set_cookie = ngx_list_push(&r->headers_out.headers);
if (set_cookie == NULL) {
return NGX_ERROR;
}

set_cookie->hash = 1;
set_cookie->key.len = sizeof("X-test42") - 1;
set_cookie->key.data = (u_char *) "X-test42";
set_cookie->value.len = sizeof("foo/bar") - 1;
set_cookie->value.data = (u_char *)"foo/bar";

return ngx_http_next_header_filter(r);
}

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] problem with a sample module

Jérôme Loyet 4114 June 01, 2010 02:38AM

Re: [nginx] problem with a sample module

Igor Sysoev 1245 June 01, 2010 02:44AM

Re: [nginx] problem with a sample module

Jérôme Loyet 1081 June 01, 2010 03:26AM

Re: [nginx] problem with a sample module

Jérôme Loyet 1217 June 01, 2010 04:42AM

Re: [nginx] problem with a sample module

agentzh 1081 June 01, 2010 05:00AM

Re: [nginx] problem with a sample module

Jérôme Loyet 1396 June 01, 2010 05:04AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 166
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready