From: Andrew Cowan Date: 2008-04-16T14:18:47+09:00 Subject: Re: Question regarding mechanize lib Jesus, please ignore my last response about this, after playing with subclassing I found this works well. I didn't realize the set_headers method was called automatically and provided the objects it is passed by Mechanize, this does work to allow custom headers to be added. Thanks for pointing this out! -Andy Jes�s Gabriel y Gal�n wrote: > On Tue, Apr 15, 2008 at 8:22 PM, Andrew Cowan wrote: > >> Thanks Shawn, I wish it did help. I need a way to set custom request >> headers, from what I can tell Mechanize doesn't have a public method for >> doing that, so I may likely have to revert to net/http instead. Was hoping I >> was wrong and was just missing something... ;) >> > > I found this in the docs: > > http://mechanize.rubyforge.org/mechanize/ > > go to the CHANGELOG.txt file, and there you can find this: > > 0.6.4 > [...] > * Added protected method Mechanize#set_headers so that subclasses > can set custom headers. > rubyforge.org/tracker/?func=detail&aid=7208&group_id=1453&atid=5712 > > If you follow the link to the tracker you can see an example: > > Mechanize can now be subclassed to add any headers a user may > want. For example: > > class A < WWW::Mechanize > def set_headers(u, r, c) > super(uri, request, cur_page) > request.add_field('Cookie', 'name=Aaron') > request > end > end > > I haven't been able to test it, but it seems you can use this to > achieve what you want. Beware that in the example the params of the > method should actually be uri, request, cur_page instead of u,r,c. > > Hope this helps, > > Jesus. > > > >