# ActiveResource: Howto use custom header fields

**URL:** <https://www.ruby-forum.com/t/activeresource-howto-use-custom-header-fields/103119>\
**Category:** Rails\
**Created:** [May 2, 2007, 12:54am UTC](https://www.ruby-forum.com/t/activeresource-howto-use-custom-header-fields/103119 "2007-05-02T00:54:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmanruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@cmanruby](https://www.ruby-forum.com/u/cmanruby)\
**Post date:** [May 2, 2007, 12:54am UTC](https://www.ruby-forum.com/t/activeresource-howto-use-custom-header-fields/103119/1 "2007-05-02T00:54:12Z")

</div>

Hi,

I’m using the ActiveResource (beta) gem. I need to change the header  
fields for the request.  
There is “default\_header” in ActiveResource::Connection which is  
“Content-type: application/xml”. I do not see how to change that.  
Could someone give me a hint.

TIA & regards,  
chris

---

<div class="post-metadata">

**Author:** ![cmanruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@cmanruby](https://www.ruby-forum.com/u/cmanruby)\
**Post date:** [May 2, 2007, 2:29am UTC](https://www.ruby-forum.com/t/activeresource-howto-use-custom-header-fields/103119/2 "2007-05-02T02:29:17Z")

</div>

> There is “default\_header” in ActiveResource::Connection which is  
> “Content-type: application/xml”. I do not see how to change that.  
> Could someone give me a hint.

class Project \< ActiveResource::Base  
headers[‘X-Token’] = ‘foo’  
end

Adds the X-Token header to all requests.

---

<div class="post-metadata">

**Author:** ![cmanruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@cmanruby](https://www.ruby-forum.com/u/cmanruby)\
**Post date:** [May 2, 2007, 3:18pm UTC](https://www.ruby-forum.com/t/activeresource-howto-use-custom-header-fields/103119/3 "2007-05-02T15:18:19Z")

</div>

2007/5/2, DHH [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

Hello,

> > There is “default\_header” in ActiveResource::Connection which is  
> > “Content-type: application/xml”. I do not see how to change that.  
> > Could someone give me a hint.

> class Project \< ActiveResource::Base  
> headers[‘X-Token’] = ‘foo’  
> end
> 
> Adds the X-Token header to all requests.

Thank you for your help. The “headers” methods isn’t yet included in  
the ActiveResource gem. However, due to your hint, I downloaded at the  
SVN sources and it works.

regards,  
chris

---

<div class="post-metadata">

**Author:** ![cmanruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@cmanruby](https://www.ruby-forum.com/u/cmanruby)\
**Post date:** [May 3, 2007, 12:25am UTC](https://www.ruby-forum.com/t/activeresource-howto-use-custom-header-fields/103119/4 "2007-05-03T00:25:31Z")

</div>

> Thank you for your help. The “headers” methods isn’t yet included in  
> the ActiveResource gem. However, due to your hint, I downloaded at the  
> SVN sources and it works.

Pushed the latest as beta gems.
