# Question on module user context

**URL:** <https://www.ruby-forum.com/t/question-on-module-user-context/165295>\
**Category:** NGINX\
**Created:** [April 11, 2009, 5:12pm UTC](https://www.ruby-forum.com/t/question-on-module-user-context/165295 "2009-04-11T17:12:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Delta\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f9ae1b/32.png) [@Delta\_Y](https://www.ruby-forum.com/u/Delta_Y)\
**Post date:** [April 11, 2009, 5:12pm UTC](https://www.ruby-forum.com/t/question-on-module-user-context/165295/1 "2009-04-11T17:12:31Z")

</div>

Hi ,  
If I set a context to a module with ngx\_http\_set\_ctx(r, c, module)  
Is this context valid only for current http request?  
Should I set the context for each new http request?

BR,  
DeltaY

---

<div class="post-metadata">

**Author:** ![Delta\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f9ae1b/32.png) [@Delta\_Y](https://www.ruby-forum.com/u/Delta_Y)\
**Post date:** [April 11, 2009, 5:28pm UTC](https://www.ruby-forum.com/t/question-on-module-user-context/165295/2 "2009-04-11T17:28:55Z")

</div>

Hello!

On Sat, Apr 11, 2009 at 11:04:14PM +0800, Delta Y. wrote:

> Hi ,  
> If I set a context to a module with ngx\_http\_set\_ctx(r, c, module)  
> Is this context valid only for current http request?

Yes.

> Should I set the context for each new http request?

No, only for requests where you actually need context.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Delta\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f9ae1b/32.png) [@Delta\_Y](https://www.ruby-forum.com/u/Delta_Y)\
**Post date:** [April 11, 2009, 5:41pm UTC](https://www.ruby-forum.com/t/question-on-module-user-context/165295/3 "2009-04-11T17:41:48Z")

</div>

2009/4/11 Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> > Should I set the context for each new http request?
> 
> No, only for requests where you actually need context.

So the context is used for the scenario that the handler callback will  
be  
called multiple times to process the http request ?

---

<div class="post-metadata">

**Author:** ![Delta\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f9ae1b/32.png) [@Delta\_Y](https://www.ruby-forum.com/u/Delta_Y)\
**Post date:** [April 11, 2009, 9:58pm UTC](https://www.ruby-forum.com/t/question-on-module-user-context/165295/4 "2009-04-11T21:58:15Z")

</div>

Hello!

On Sat, Apr 11, 2009 at 11:33:22PM +0800, Delta Y. wrote:

> > Yes.
> > 
> > > Should I set the context for each new http request?
> > 
> > No, only for requests where you actually need context.
> 
> So the context is used for the scenario that the handler callback will be  
> called multiple times to process the http request ?

Yes, it’s used to preserve some request-related state between  
invocations of your module code.

Maxim D.
