# Return custom http responses from a controller?

**URL:** <https://www.ruby-forum.com/t/return-custom-http-responses-from-a-controller/108217>\
**Category:** Rails\
**Created:** [June 30, 2007, 6:03am UTC](https://www.ruby-forum.com/t/return-custom-http-responses-from-a-controller/108217 "2007-06-30T06:03:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [June 30, 2007, 6:03am UTC](https://www.ruby-forum.com/t/return-custom-http-responses-from-a-controller/108217/1 "2007-06-30T06:03:58Z")

</div>

Is it possible to have a response to the browser triggered prematurely  
in a controller? like before rails does all it’s internal processing?

also if so can I change the content-type for the response?

thanks

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [June 30, 2007, 6:04am UTC](https://www.ruby-forum.com/t/return-custom-http-responses-from-a-controller/108217/2 "2007-06-30T06:04:32Z")

</div>

Aaron S. wrote:

> Is it possible to have a response to the browser triggered prematurely  
> in a controller? like before rails does all it’s internal processing?
> 
> also if so can I change the content-type for the response?
> 
> thanks

Also, besides the content-type, how can I supply a custom response body?

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [June 30, 2007, 6:24am UTC](https://www.ruby-forum.com/t/return-custom-http-responses-from-a-controller/108217/3 "2007-06-30T06:24:53Z")

</div>

On 6/29/07, Aaron S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Aaron S. wrote:
> 
> > Is it possible to have a response to the browser triggered prematurely  
> > in a controller? like before rails does all it’s internal processing?
> > 
> > also if so can I change the content-type for the response?
> > 
> > thanks
> 
> Also, besides the content-type, how can I supply a custom response body?

render is what supplies the response body. There are just more ways  
to render then you are aware of. render :text =\> ‘test’, render  
:file =\>file, render\_xml, etc…

To set headers do this before rendering:

headers[“Content-Type”] = ‘mycontenttype’

Chris

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [June 30, 2007, 6:55am UTC](https://www.ruby-forum.com/t/return-custom-http-responses-from-a-controller/108217/4 "2007-06-30T06:55:32Z")

</div>

perfect. thanks.
