Issue #1000 resolved

request.methods_with_bodies logic is run before the "before_request_body" hooks are run

Anonymous created an issue

I was writing a REST interface for a project of mine and I was having a heck of a time trying to get cherrypy to give me ''request.body'' for a DELETE method. I tried setting the ''methods_with_bodies'' member of ''request'' to ('POST', 'PUT', 'DELETE'), but it would seemingly have no effect.

So I poked around in the code to find where this variable was being processed. Apparently, the logic that sets ''process_request_body'' based off ''methods_with_bodies'' is run before the hooks for 'before_request_body' are run. Thus, while I thought that hook would be the correct time to set this '''body processing variable''', it appears I need to use the preceding hook.

source:trunk/cherrypy/ {{{ 643 # Process the body 644 if self.process_request_body: 645 if self.method not in self.methods_with_bodies: 646 self.process_request_body = False 647 self.stage = 'before_request_body' 648'before_request_body') 649 if self.process_request_body: 650 self.body.process() }}}

I don't know if there is some design decision that makes the code behave this way, but it's certainly not intuitive. I think it should either be changed to run after the hooks or the documentation for ''methods_with_bodies'' needs to be updated to reflect this situation. The only problem I foresee with moving the hook code above where it is now, is that if ''process_request_body'' is manually set in a hook, it would be overridden with the ''methods_with_bodies'' logic. Perhaps a new flag, say a ''manual_body_processing'' flag, should be created that is different from the one set by ''methods_with_bodies''.

Reported by

Comments (1)

  1. Log in to comment