> No, with Mahmoud's suggestion the subclass's handler methods have
> names like "Get" and "Post". The framework calls the "get" and "post"
> methods of base class which in turn calls the "Get" and "Post" methods
> of the subclass.
I just tried this..unless I'm doing something wrong, though, the super
class function is not invoked unless you call it explicitly in the
overriding subclass function. This is what I mean by an extra line of
code in the subclass handler functions. Again, maybe I'm not fully
understanding python inheritance, but it doesn't seem to work for me
without a BaseClass.get() call or BaseClass.post() call in the sub-
class handlers.
Not that this is necessarily a HUGE deal, but I've actually run into
the same issue again of the script continuing to execute and appending
a body to the response, with the data that's supposed to be protected,
if the user just even hits cancel on the user/password prompt. To
perhaps be a little clearer, if the authorization header isn't there
or contains incorrect credentials, this function is called:
def forbidden(self):
self.response.headers['WWW-Authenticate'] = 'Basic realm=Cocom'
self.response.set_status(401)
When overriding the RequestHandler's initialize or handler functions
to call this first, this doesn't stop the rest of the script executing
and appending the supposedly protected data to the response's body. I
tried using sys.exit() and raise SystemExit, but neither seems to work
(they give me an error).
However, if I override the WSGIApplication __call__ function, then
that forbidden method can look like this:
def forbidden(self,start_response):
response = webapp.Response()
response.headers['WWW-Authenticate'] = 'Basic realm=Cocom'
response.set_status(401)
response.wsgi_write(start_response)
This seems to immediately respond to the request with a 401, and no
further data (although I admit I'm uneasy to know what exactly happens
after this code has executed..does the rest of the handler execute,
and if so, what happens to the data it generates?). And it is a bit
more hack-y to override this than to subclass the RequestHandler
class, for sure. Unfortunately, like I said earlier, the
wsti_write(start_response) bit, which seems to trigger the immediate
response, doesn't seem to work in overrides of RequestHandler
functions.
I've a feeling there must be a very simple answer to all this that I'm
missing :) Thanks so much for your patience and help..