# Modifying response body

**URL:** <https://www.ruby-forum.com/t/modifying-response-body/167322>\
**Category:** NGINX\
**Created:** [May 6, 2009, 6:05pm UTC](https://www.ruby-forum.com/t/modifying-response-body/167322 "2009-05-06T18:05:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [May 6, 2009, 6:05pm UTC](https://www.ruby-forum.com/t/modifying-response-body/167322/1 "2009-05-06T18:05:52Z")

</div>

2 questions:  
Is it possible to return an empty response? i.e.  
location /empty-response {  
add\_header(“some-header”, “foo-bar”);  
# nothing in response body  
}

Is it possible have the response body be only the unique id set by the  
userid module? i.e.  
userid on;  
location /unique-id {  
# response body should be “uid=\<cookie’s uid\>”  
}

Thanks,  
Joe

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [May 6, 2009, 9:10pm UTC](https://www.ruby-forum.com/t/modifying-response-body/167322/2 "2009-05-06T21:10:09Z")

</div>

Hello!

On Wed, May 06, 2009 at 08:57:31AM -0700, Joe Van D. wrote:

> 2 questions:  
> Is it possible to return an empty response? i.e.  
> location /empty-response {  
> add\_header(“some-header”, “foo-bar”);  
> # nothing in response body  
> }

Something like

```
location /empty-response {
    add_header ...;
    return 204;
}

```

should work for http-complaint applications (but not some popular  
browsers).

> Is it possible have the response body be only the unique id set by the  
> userid module? i.e.  
> userid on;  
> location /unique-id {  
> # response body should be “uid=\<cookie’s uid\>”  
> }

Either use embedded perl or try http\_response module by Kirill  
Korinskiy  
([http://catap.ru/downloads/nginx/ngx\_http\_response-0.3.tar.gz](http://catap.ru/downloads/nginx/ngx_http_response-0.3.tar.gz)).

Maxim D.

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [May 6, 2009, 11:48pm UTC](https://www.ruby-forum.com/t/modifying-response-body/167322/3 "2009-05-06T23:48:36Z")

</div>

Hello!

On Wed, May 06, 2009 at 12:49:30PM -0700, Joe Van D. wrote:

> > > ```
> > > # nothing in response body
> > > 
> > > ```
> > 
> > browsers).
> 
> I earlier tried returning a 200 and it seemed to hang on me. Maybe browser  
> problem?

No, returning 200 won’t do anything good. For now it will  
basically instruct nginx to “forgot” about request without sending  
anything (pretending reply was already sent).

Returning 204 should work as it returns correct HTTP reply with  
empty content - but AFAIK at least IE have problems with it.

> Thanks. I think I will just proxy the request to a Sinatra app, even though  
> I’m losing a lot of performance. Is that module for nginx 0.6.x?

It should work for both 0.6.\* and 0.7.\*.

Looks like it doesn’t compile with 0.7.53+ due to trivial unused  
function declaration warning though. But it’s really trivial to  
fix even without C knowledge (just remove offending line or  
./configure nginx with --with-cc-opt=“-Wno-error”).

Maxim D.

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [May 6, 2009, 9:57pm UTC](https://www.ruby-forum.com/t/modifying-response-body/167322/4 "2009-05-06T21:57:05Z")

</div>

On Wed, May 6, 2009 at 12:02 PM, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Something like
> 
> location /empty-response {  
> add\_header …;  
> return 204;  
> }
> 
> should work for http-complaint applications (but not some popular  
> browsers).

I earlier tried returning a 200 and it seemed to hang on me. Maybe  
browser  
problem?

> > Is it possible have the response body be only the unique id set by the  
> > userid module? i.e.  
> > userid on;  
> > location /unique-id {  
> > # response body should be “uid=\<cookie’s uid\>”  
> > }
> 
> Either use embedded perl or try http\_response module by Kirill  
> Korinskiy ([http://catap.ru/downloads/nginx/ngx\_http\_response-0.3.tar.gz](http://catap.ru/downloads/nginx/ngx_http_response-0.3.tar.gz)).

Thanks. I think I will just proxy the request to a Sinatra app, even  
though  
I’m losing a lot of performance. Is that module for nginx 0.6.x?
