Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add spec to HTTPRequest/Application.__call__ #853

Open
wants to merge 2 commits into
from

Conversation

Projects
None yet
2 participants

I found for both debugging and logic I needed to know which spec was used. If this is otherwise attainable I would love to know.

Here's my simple patch to get this going.

whardier added some commits Jul 15, 2013

Update web.py
add request.spec assignment to matching spec
Update httpserver.py
Added spec variable (None)
Owner

bdarnell commented Jul 16, 2013

The layering here feels wrong. HTTPServer can be used without any of the classes in tornado.web, so it's strange to add a field to httpserver.HTTPRequest that is not generally applicable. On the other hand, there's not another good place to stash this information (unless we decide that overriding RequestHandler.__init__ has been deprecated long enough and everyone should move to overriding initialize. Then we could add additional arguments to the RequestHandler constructor).

For now, the official way to tell which URLSpec matched is to use the kwargs dictionary to pass some unique value to initialize:

in RequestHandler subclass

def initialized(self, spec_name):
self.spec_name = spec_name

in Application initializer

(r'/foo', FooHandler, dict(spec_name='foo')),

I was afraid of that :)

Cheers Ben and thanks for giving this a moments thought. My urlspecs are
becoming more visually stimulating than I had hoped!

On Mon, Jul 15, 2013 at 5:28 PM, bdarnell notifications@github.com wrote:

The layering here feels wrong. HTTPServer can be used without any of the
classes in tornado.web, so it's strange to add a field to
httpserver.HTTPRequest that is not generally applicable. On the other hand,
there's not another good place to stash this information (unless we decide
that overriding RequestHandler.init has been deprecated long enough
and everyone should move to overriding initialize. Then we could add
additional arguments to the RequestHandler constructor).

For now, the official way to tell which URLSpec matched is to use the
kwargs dictionary to pass some unique value to initialize:

in RequestHandler subclass

def initialized(self, spec_name):
self.spec_name = spec_name

in Application initializer

(r'/foo', FooHandler, dict(spec_name='foo')),


Reply to this email directly or view it on GitHubhttps://github.com/facebook/tornado/pull/853#issuecomment-21015772
.

@bdarnell bdarnell added the web label Jul 16, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment