what is the cleanest way to do something for every request of a particular type (Verb, and Content-Type header)? i''m trying to figure out if shipping a custom camping.rb is avoidable, and if, how i should structure a patch my app http://whats-your.name/yard/ uses exclusively JSON based messaging between server and client. this means POST bodies are JSON, and not querystring.. camping assumes: elsif @method == "post" qs.merge!(C.qsp(@in.read)) if i patch to: elsif @method == "post" case e.CONTENT_TYPE when "application/x-www-form-urlencoded" qs.merge!(C.qsp(@in.read)) when "application/json" @input = JSON.parse(@in.read)) end theres two probs, 1) you now have to always make sure you send the x-www-form-urlencoded header (weird browsers, or XHR requests might not), 2) @input is overwritten by qs.dup, input isnt a query string! i tried using a custom verb, which works fine in firefox, but not WebKit-QT4-Linux.. RFC 2616 does not specify a format for the data in a POST body, and the overall function of the request is consistent with POST. what do i do? :)
2007/4/18, carmen <_ at whats-your.name>:> what is the cleanest way to do something for every request of a particular type (Verb, and Content-Type header)? i''m trying to figure out if shipping a custom camping.rb is avoidable, and if, how i should structure a patch > > > my app http://whats-your.name/yard/ uses exclusively JSON based messaging between server and client. this means POST bodies are JSON, and not querystring.. camping assumes: > > elsif @method == "post" > qs.merge!(C.qsp(@in.read)) > > if i patch to: > > elsif @method == "post" > case e.CONTENT_TYPE > when "application/x-www-form-urlencoded" > qs.merge!(C.qsp(@in.read)) > when "application/json" > @input = JSON.parse(@in.read)) > end > > theres two probs, 1) you now have to always make sure you send the x-www-form-urlencoded header (weird browsers, or XHR requests might not), 2) @input is overwritten by qs.dup, input isnt a query string! > > i tried using a custom verb, which works fine in firefox, but not WebKit-QT4-Linux.. RFC 2616 does not specify a format for the data in a POST body, and the overall function of the request is consistent with POST. > > what do i do? :)Hi Carmen, to avoid patching Camping, I suggest you look into overriding the "service" method for the target controllers. You can do this in your main application module or by including a custom module in your controllers, as you prefer. Let me know if you need more hints. -- Cheers, zimbatm
On 4/18/07, Jonas Pfenniger <zimbatm at oree.ch> wrote:> > Hi Carmen, > > to avoid patching Camping, I suggest you look into overriding the > "service" method for the target controllers. You can do this in your > main application module or by including a custom module in your > controllers, as you prefer. Let me know if you need more hints.I was going to suggest the same thing, but when I looked at it, it wasn''t clear if this would allow for grabbing data like the request headers (allowing you to determine what form the submitted data takes). Based on the code Carmen posted, it looks like the idea is to be able to use the same controllers whether the data comes in from regular requests or as JSON data. Granted, that could still be done in the controllers, but it does end up being a bit less elegant. -- Thomas Lockney | tlockney at gmail.com | http://opposable-thumbs.net -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/camping-list/attachments/20070418/bf3f649d/attachment.html
> controllers whether the data comes in from regular requests or as JSON data. > Granted, that could still be done in the controllers, but it does end up > being a bit less elegant.the main idea is always get @input in the controller regardless of the format - currently it unnecessarily parses the POST data trying to get querystring values out of the JSON maybe that method should be split up? it already combines the file upload mangling, and GET and POST querystring parsing.. i will be using formats besides JSON to set @input too... Turtle, for example..> > -- > Thomas Lockney | tlockney at gmail.com | http://opposable-thumbs.net> _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list
2007/4/18, Thomas Lockney <tlockney at gmail.com>:> On 4/18/07, Jonas Pfenniger <zimbatm at oree.ch> wrote: > > Hi Carmen, > > > > to avoid patching Camping, I suggest you look into overriding the > > "service" method for the target controllers. You can do this in your > > main application module or by including a custom module in your > > controllers, as you prefer. Let me know if you need more hints. > > I was going to suggest the same thing, but when I looked at it, it wasn''t > clear if this would allow for grabbing data like the request headers > (allowing you to determine what form the submitted data takes). Based on the > code Carmen posted, it looks like the idea is to be able to use the same > controllers whether the data comes in from regular requests or as JSON data. > Granted, that could still be done in the controllers, but it does end up > being a bit less elegant.Yes, Camping could probably benefit from some method splitting here. I feel like this method is too big and not really correct. I don''t think that it should put the posted data in a Tempfile, especially if your controller will never make a use of it. I''m not sure it follows the RFC too. Btw I''ve spotted some debug line here that could be removed : http://code.whytheluckystiff.net/camping/browser/trunk/lib/camping-unabridged.rb#L402 -- Cheers, zimbatm
On Wed Apr 18, 2007 at 08:38:30PM +0200, Jonas Pfenniger wrote:> 2007/4/18, Thomas Lockney <tlockney at gmail.com>: > > On 4/18/07, Jonas Pfenniger <zimbatm at oree.ch> wrote: > > > Hi Carmen, > > > > > > to avoid patching Camping, I suggest you look into overriding the > > > "service" method for the target controllers. You can do this in your > > > main application module or by including a custom module in your > > > controllers, as you prefer. Let me know if you need more hints. > > > > I was going to suggest the same thing, but when I looked at it, it wasn''t > > clear if this would allow for grabbing data like the request headers > > (allowing you to determine what form the submitted data takes). Based on the > > code Carmen posted, it looks like the idea is to be able to use the same > > controllers whether the data comes in from regular requests or as JSON data. > > Granted, that could still be done in the controllers, but it does end up > > being a bit less elegant. > > Yes, Camping could probably benefit from some method splitting here. Iperhaps, but> feel like this method is too big and not really correct. I don''t think > that it should put the posted data in a Tempfile, especially if your > controller will never make a use of it. I''m not sure it follows the > RFC too. > > Btw I''ve spotted some debug line here that could be removed : > http://code.whytheluckystiff.net/camping/browser/trunk/lib/camping-unabridged.rb#L402it appears -r188 added the patch i needed to use the service method without the unecessary parsing.. /me remembers what i was taught in first grade - always SVN up first!> > -- > Cheers, > zimbatm > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list >
gem install --source http://code.whytheluckystiff.net camping Need to update 3 gems from http://code.whytheluckystiff.net ... complete ERROR: While executing gem ... (TypeError) gem install camping-omnibus --source http://code.whytheluckystiff.net Install required dependency camping? [Yn] y ERROR: While executing gem ... (TypeError) can''t convert Hash into String ruby -v ruby 1.8.6 (2007-03-13 patchlevel 0) [x86_64-linux] /me scurries off to manually check out
Try removing ~/.gem/source_cache first 2007/4/18, carmen <_ at whats-your.name>:> gem install --source http://code.whytheluckystiff.net camping > Need to update 3 gems from http://code.whytheluckystiff.net > ... > complete > ERROR: While executing gem ... (TypeError) > > > gem install camping-omnibus --source http://code.whytheluckystiff.net > Install required dependency camping? [Yn] y > ERROR: While executing gem ... (TypeError) > can''t convert Hash into String > > ruby -v > ruby 1.8.6 (2007-03-13 patchlevel 0) [x86_64-linux] > > /me scurries off to manually check out > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list >-- Cheers, zimbatm
On Wed Apr 18, 2007 at 10:46:34PM +0200, Jonas Pfenniger wrote:> Try removing ~/.gem/source_cache firstthat isnt it, rubygems just keeps on proving it hates me [1] SVN head didnt like me either: NoMethodError undefined method `capture'' for #<Array:0x2b8c0f1cc7f0> in #render so it was back to r180 cp -av''d from another machine since rubygems isnt working definitely investigating tiny lua httpds tho, since redland''s bindings like to segfault the ruby interp (well, i dont know whose fault it is, other than it happens a lot) 1. http://rubyforge.org/pipermail/mongrel-users/2007-January/002753.html> > 2007/4/18, carmen <_ at whats-your.name>: > > gem install --source http://code.whytheluckystiff.net camping > > Need to update 3 gems from http://code.whytheluckystiff.net > > ... > > complete > > ERROR: While executing gem ... (TypeError) > > > > > > gem install camping-omnibus --source http://code.whytheluckystiff.net > > Install required dependency camping? [Yn] y > > ERROR: While executing gem ... (TypeError) > > can''t convert Hash into String > > > > ruby -v > > ruby 1.8.6 (2007-03-13 patchlevel 0) [x86_64-linux] > > > > /me scurries off to manually check out > > _______________________________________________ > > Camping-list mailing list > > Camping-list at rubyforge.org > > http://rubyforge.org/mailman/listinfo/camping-list > > > > > -- > Cheers, > zimbatm > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list >
in the service method (or any controller method), is there a way to access the incoming request headers? @headers is initialized to {''Content-Type''=>''text/html''} for the response at this point.. im wondering if the request is already sitting around in some instance var, or setting e to @e in initialize is the best solution..
On Thu Apr 19, 2007 at 01:17:30PM -0400, carmen wrote:> in the service method (or any controller method), is there a way to access the incoming request headers? @headers is initialized to {''Content-Type''=>''text/html''} for the response at this point.. > > im wondering if the request is already sitting around in some instance var, or setting e to @e in initialize is the best solution..nevermind, discovered @env about 30 seconds into the 300 second greylist period, and no idea to cancel the pending message in that time..> _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list >