# HTTP Request filter module

**URL:** <https://www.ruby-forum.com/t/http-request-filter-module/213475>\
**Category:** NGINX\
**Created:** [November 3, 2011, 8:07am UTC](https://www.ruby-forum.com/t/http-request-filter-module/213475 "2011-11-03T08:07:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [November 3, 2011, 8:07am UTC](https://www.ruby-forum.com/t/http-request-filter-module/213475/1 "2011-11-03T08:07:03Z")

</div>

I have a requirement for HTTP request filter. Whenever I receive a HTTP  
request this filter module should read the request and does some  
internal statistical work, it doesn’t manipulate the request page nor  
creates response page. It just need to peep into request that’s it.  
After this filter module, nginx HTTP server should continue to process  
the request and serve the response to user. Can we do it without a proxy  
handler, because nginx serves the responses directly here.

Please help me.

Posted at Nginx Forum:

> **[HTTP Request filter module](https://forum.nginx.org/read.php?2,217739,217739#msg-217739)**
>
> I have a requirement for HTTP request filter. Whenever I receive a HTTP request this filter module should read the request and does some internal statistical work, it doesn't manipulate the request page nor creates response page. It just need to peep...

---

<div class="post-metadata">

**Author:** ![forum\_id](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/838e76/32.png) [@forum\_id](https://www.ruby-forum.com/u/forum_id)\
**Post date:** [November 3, 2011, 11:42am UTC](https://www.ruby-forum.com/t/http-request-filter-module/213475/2 "2011-11-03T11:42:27Z")

</div>

Doesn’t post\_action do what you need?  
[http://wiki.nginx.org/HttpCoreModule#post\_action](http://wiki.nginx.org/HttpCoreModule#post_action)

---

<div class="post-metadata">

**Author:** ![forum\_id](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/838e76/32.png) [@forum\_id](https://www.ruby-forum.com/u/forum_id)\
**Post date:** [November 3, 2011, 12:01pm UTC](https://www.ruby-forum.com/t/http-request-filter-module/213475/3 "2011-11-03T12:01:03Z")

</div>

On Thu, Nov 3, 2011 at 3:06 PM, forum\_id [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a requirement for HTTP request filter. Whenever I receive a HTTP  
> request this filter module should read the request and does some  
> internal statistical work, it doesn’t manipulate the request page nor  
> creates response page. It just need to peep into request that’s it.  
> After this filter module, nginx HTTP server should continue to process  
> the request and serve the response to user. Can we do it without a proxy  
> handler, because nginx serves the responses directly here.

I think this is a perfect use case for the rewrite\_by\_lua or  
access\_by\_lua directives provided by the ngx\_lua module. See

[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpLuaModule)

You can read and modify the request URI, query args, or even request  
bodies in your Lua code and save the statistical results in the  
shm-based dictionary (shared\_dict) provided by ngx\_lua or issue a  
subrequest from within Lua to internal locations configured by  
ngx\_memc or ngx\_redis2 via the ngx.location.capture API.

Because LuaJIT 2.0 is so light and so fast, this setting can achieve  
performance comparable with an Nginx C module and also provide  
scripting flexibility 🙂

Regards,  
-agentzh

---

<div class="post-metadata">

**Author:** ![forum\_id](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/838e76/32.png) [@forum\_id](https://www.ruby-forum.com/u/forum_id)\
**Post date:** [November 3, 2011, 1:12pm UTC](https://www.ruby-forum.com/t/http-request-filter-module/213475/4 "2011-11-03T13:12:53Z")

</div>

Thank you. I am new to nginx, so spare me if I talk anything nonsense. I  
want through link you provided, and then went through code as well. I  
couldn’t understand few things here

1. Can we override nginx core’s directive?
2. Since that post action is been used in multiple place, how far it  
safe to over write it?

Thank you once again.

Posted at Nginx Forum:

> **[Re: HTTP Request filter module](https://forum.nginx.org/read.php?2,217739,217761#msg-217761)**
>
> I have a requirement for HTTP request filter. Whenever I receive a HTTP request this filter module should read the request and does some internal statistical work, it doesn't manipulate the request page nor creates response page. It just need to peep...

---

<div class="post-metadata">

**Author:** ![forum\_id](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/838e76/32.png) [@forum\_id](https://www.ruby-forum.com/u/forum_id)\
**Post date:** [November 3, 2011, 1:55pm UTC](https://www.ruby-forum.com/t/http-request-filter-module/213475/5 "2011-11-03T13:55:36Z")

</div>

On Thu, Nov 3, 2011 at 8:13 PM, forum\_id [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thank you. As per the project requirements need to develop C modules  
> only, so if @agentzh can suggest me in this way, that would be helpful.

Just take a look at how ngx\_lua does those things on the C level 🙂

Regards,  
-agentzh

---

<div class="post-metadata">

**Author:** ![forum\_id](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/838e76/32.png) [@forum\_id](https://www.ruby-forum.com/u/forum_id)\
**Post date:** [November 4, 2011, 11:51am UTC](https://www.ruby-forum.com/t/http-request-filter-module/213475/6 "2011-11-04T11:51:13Z")

</div>

@agentzh, thank you. As you suggested, I went through the ngx\_lua code.  
Since I am new to nginx, my understanding was not so good, but I want to  
write it in few points,

1. Lua handler receives request
2. Forwards request to Lua interpreter
3. Send Lua response back to user.

Let me know if my understanding itself is wrong. Give me some simple  
pointers to understand, because I need to start with my module as soon  
as possible. Thank you once again.

Posted at Nginx Forum:

> **[Re: HTTP Request filter module](https://forum.nginx.org/read.php?2,217739,217810#msg-217810)**
>
> I have a requirement for HTTP request filter. Whenever I receive a HTTP request this filter module should read the request and does some internal statistical work, it doesn't manipulate the request page nor creates response page. It just need to peep...

---

<div class="post-metadata">

**Author:** ![forum\_id](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/838e76/32.png) [@forum\_id](https://www.ruby-forum.com/u/forum_id)\
**Post date:** [November 4, 2011, 2:03pm UTC](https://www.ruby-forum.com/t/http-request-filter-module/213475/7 "2011-11-04T14:03:00Z")

</div>

On Fri, Nov 4, 2011 at 6:50 PM, forum\_id [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> @agentzh, thank you. As you suggested, I went through the ngx\_lua code.  
> Since I am new to nginx, my understanding was not so good, but I want to  
> write it in few points,

If you’re not familiar with Nginx internals, then I think use ngx\_lua  
and Lua scripting is the quickest and easiest way to get the job done.  
I don’t think I have the time to explain every thing here because it’s  
really complicated for freshmen 🙂

If you insist in Nginx C module development, I suggest you start with  
the resources listed here:

```
http://wiki.nginx.org/Resources

```

Regards,  
-agentzh

---

<div class="post-metadata">

**Author:** ![forum\_id](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/838e76/32.png) [@forum\_id](https://www.ruby-forum.com/u/forum_id)\
**Post date:** [November 3, 2011, 1:14pm UTC](https://www.ruby-forum.com/t/http-request-filter-module/213475/8 "2011-11-03T13:14:07Z")

</div>

Thank you. As per the project requirements need to develop C modules  
only, so if @agentzh can suggest me in this way, that would be helpful.

Posted at Nginx Forum:

> **[Re: HTTP Request filter module](https://forum.nginx.org/read.php?2,217739,217762#msg-217762)**
>
> I have a requirement for HTTP request filter. Whenever I receive a HTTP request this filter module should read the request and does some internal statistical work, it doesn't manipulate the request page nor creates response page. It just need to peep...

---

<div class="post-metadata">

**Author:** ![forum\_id](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/838e76/32.png) [@forum\_id](https://www.ruby-forum.com/u/forum_id)\
**Post date:** [November 4, 2011, 3:12pm UTC](https://www.ruby-forum.com/t/http-request-filter-module/213475/9 "2011-11-04T15:12:23Z")

</div>

@agentzh, thank you. Even though I am new to nginx I went through to  
understand how nginx works and understood how nginx modules work. I just  
need very few pointers, like lua modules receives request and forwards  
to lua interpreter, after processing the request how it sends details. I  
need to overall details not complete in depth details, so that I can  
spend more time on code in productive way. It will make easy to  
understand in better way. I need to use C language. Please give very  
small notes with 5 points are also fine for me to start on it.

Posted at Nginx Forum:

> **[Re: HTTP Request filter module](https://forum.nginx.org/read.php?2,217739,217820#msg-217820)**
>
> I have a requirement for HTTP request filter. Whenever I receive a HTTP request this filter module should read the request and does some internal statistical work, it doesn't manipulate the request page nor creates response page. It just need to peep...
