Aaron Patterson
2008-Mar-04 12:06 UTC
[Eventmachine-talk] EventMachine and leveraging net/http
Hi all, I''ve finally found time to try "eventing" WWW::Mechanize. As far as I can tell, Event Machine doesn''t let me set many custom headers. I was wondering if anyone had considered allowing request objects like Net::HTTP::Get or Net::HTTP::Post to be passed in? Then you could set arbitrary headers, and have code like this: EventMachine.run { request = Net::HTTP::Get.new(''/'') request[''accept-encoding''] = ''gzip,identity'' request[''accept-language''] = ''en-us,en,q=0.5'' request[''user-agent''] = ''test agent'' c = EventMachine::Protocols::HttpClient.send :request, :host => ''google.com'', :port => 80, :request_obj => request c.callback { |result| p result EventMachine.stop } c.errback { EventMachine.stop } } I was able to patch Event Machine pretty easily to accept a Net::HTTP request object. I even made the interface backwards compatible so all tests pass. I''ve posted the diff to make my example work here: http://pastie.caboo.se/161410 Also, it would be neat of the result was a Net::HTTPResponse type object. I haven''t really looked in to that yet though. -- Aaron Patterson http://tenderlovemaking.com/
Aaron Patterson
2008-Apr-01 17:05 UTC
[Eventmachine-talk] EventMachine and leveraging net/http
*bump* Any chance of getting this patch applied? On Tue, Mar 04, 2008 at 12:06:20PM -0800, Aaron Patterson wrote:> Hi all, > > I''ve finally found time to try "eventing" WWW::Mechanize. As far as I > can tell, Event Machine doesn''t let me set many custom headers. I was > wondering if anyone had considered allowing request objects like > Net::HTTP::Get or Net::HTTP::Post to be passed in? Then you could set > arbitrary headers, and have code like this: > > EventMachine.run { > request = Net::HTTP::Get.new(''/'') > request[''accept-encoding''] = ''gzip,identity'' > request[''accept-language''] = ''en-us,en,q=0.5'' > request[''user-agent''] = ''test agent'' > > c = EventMachine::Protocols::HttpClient.send :request, > :host => ''google.com'', > :port => 80, > :request_obj => request > c.callback { |result| > p result > EventMachine.stop > } > c.errback { EventMachine.stop } > } > > I was able to patch Event Machine pretty easily to accept a Net::HTTP > request object. I even made the interface backwards compatible so all > tests pass. I''ve posted the diff to make my example work here: > > http://pastie.caboo.se/161410 > > Also, it would be neat of the result was a Net::HTTPResponse type > object. I haven''t really looked in to that yet though. > > -- > Aaron Patterson > http://tenderlovemaking.com/ > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk-- Aaron Patterson http://tenderlovemaking.com/
On Tue, Apr 1, 2008 at 8:05 PM, Aaron Patterson <aaron at tenderlovemaking.com> wrote:> *bump* > > Any chance of getting this patch applied?+1. This looks very useful.
Aaron Patterson
2008-Jul-25 10:14 UTC
[Eventmachine-talk] EventMachine and leveraging net/http
*double bump* ? On Tue, Apr 01, 2008 at 05:05:17PM -0700, Aaron Patterson wrote:> *bump* > > Any chance of getting this patch applied? > > On Tue, Mar 04, 2008 at 12:06:20PM -0800, Aaron Patterson wrote: > > Hi all, > > > > I''ve finally found time to try "eventing" WWW::Mechanize. As far as I > > can tell, Event Machine doesn''t let me set many custom headers. I was > > wondering if anyone had considered allowing request objects like > > Net::HTTP::Get or Net::HTTP::Post to be passed in? Then you could set > > arbitrary headers, and have code like this: > > > > EventMachine.run { > > request = Net::HTTP::Get.new(''/'') > > request[''accept-encoding''] = ''gzip,identity'' > > request[''accept-language''] = ''en-us,en,q=0.5'' > > request[''user-agent''] = ''test agent'' > > > > c = EventMachine::Protocols::HttpClient.send :request, > > :host => ''google.com'', > > :port => 80, > > :request_obj => request > > c.callback { |result| > > p result > > EventMachine.stop > > } > > c.errback { EventMachine.stop } > > } > > > > I was able to patch Event Machine pretty easily to accept a Net::HTTP > > request object. I even made the interface backwards compatible so all > > tests pass. I''ve posted the diff to make my example work here: > > > > http://pastie.caboo.se/161410 > > > > Also, it would be neat of the result was a Net::HTTPResponse type > > object. I haven''t really looked in to that yet though. > > > > -- > > Aaron Patterson > > http://tenderlovemaking.com/ > > _______________________________________________ > > Eventmachine-talk mailing list > > Eventmachine-talk at rubyforge.org > > http://rubyforge.org/mailman/listinfo/eventmachine-talk > > -- > Aaron Patterson > http://tenderlovemaking.com/ > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk-- Aaron Patterson http://tenderlovemaking.com/
Can you open a ticket for this on the trac ( http://rubyeventmachine.com/newticket)? Aman On Fri, Jul 25, 2008 at 10:14 AM, Aaron Patterson < aaron at tenderlovemaking.com> wrote:> *double bump* ? > > On Tue, Apr 01, 2008 at 05:05:17PM -0700, Aaron Patterson wrote: > > *bump* > > > > Any chance of getting this patch applied? > > > > On Tue, Mar 04, 2008 at 12:06:20PM -0800, Aaron Patterson wrote: > > > Hi all, > > > > > > I''ve finally found time to try "eventing" WWW::Mechanize. As far as I > > > can tell, Event Machine doesn''t let me set many custom headers. I was > > > wondering if anyone had considered allowing request objects like > > > Net::HTTP::Get or Net::HTTP::Post to be passed in? Then you could set > > > arbitrary headers, and have code like this: > > > > > > EventMachine.run { > > > request = Net::HTTP::Get.new(''/'') > > > request[''accept-encoding''] = ''gzip,identity'' > > > request[''accept-language''] = ''en-us,en,q=0.5'' > > > request[''user-agent''] = ''test agent'' > > > > > > c = EventMachine::Protocols::HttpClient.send :request, > > > :host => '' > google.com'', > > > :port => 80, > > > :request_obj => > request > > > c.callback { |result| > > > p result > > > EventMachine.stop > > > } > > > c.errback { EventMachine.stop } > > > } > > > > > > I was able to patch Event Machine pretty easily to accept a Net::HTTP > > > request object. I even made the interface backwards compatible so all > > > tests pass. I''ve posted the diff to make my example work here: > > > > > > http://pastie.caboo.se/161410 > > > > > > Also, it would be neat of the result was a Net::HTTPResponse type > > > object. I haven''t really looked in to that yet though. > > > > > > -- > > > Aaron Patterson > > > http://tenderlovemaking.com/ > > > _______________________________________________ > > > Eventmachine-talk mailing list > > > Eventmachine-talk at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/eventmachine-talk > > > > -- > > Aaron Patterson > > http://tenderlovemaking.com/ > > _______________________________________________ > > Eventmachine-talk mailing list > > Eventmachine-talk at rubyforge.org > > http://rubyforge.org/mailman/listinfo/eventmachine-talk > > -- > Aaron Patterson > http://tenderlovemaking.com/ > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/eventmachine-talk/attachments/20080725/8c98504a/attachment.html>