Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a RobotsTag middleware #12

Closed
wants to merge 2 commits into from
Closed

Adds a RobotsTag middleware #12

wants to merge 2 commits into from

Conversation

rik
Copy link
Contributor

@rik rik commented Jun 8, 2012

and a bit of cleanup at the same time

rik added 2 commits June 7, 2012 19:33
This will prevent search engines to use Open Directory Project descriptions
by default.
from commonware.response.middleware import FrameOptionsHeader
from commonware.response.middleware import StrictTransportMiddleware
from commonware.response.middleware import (FrameOptionsHeader,
RobotsTagHeader,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent needs to line up inside the open paren, or these should stay on separate lines.

@jsocol
Copy link
Contributor

jsocol commented Jun 12, 2012

You should look at commonware.response.decorators and look at the xframe_* decorators. I think we should copy at least two concepts here. One is the @xrobots_exempt() decorator, which I alluded to in the inline comment. The other is a kinder way to let people set the X-Robots-Tag value.

There are very few values for X-Frame-Options, so it made sense to just create 3 simple decorators. There are many, many values for X-Robots-Tag, so I think in this case you want a slightly more complex decorator:

def xrobots_tag(rule='nofollow'):
    def _decorator(f):
        @wraps(f)
        def _wrapped(req, *a, **kw):
            res = f(req, *a, **kw)
            res['x-robots-tag'] = rule
            return res
         return _wrapped
    return _decorator

Then people can more easily do

@xrobots_tag('noindex,nofollow')
def myview(request):
    pass

@jsocol
Copy link
Contributor

jsocol commented Jun 12, 2012

NB, I am also asking for an @xrobots_exempt decorator but you should basically be able to copypasta @xframe_allow for that one.

@jsocol
Copy link
Contributor

jsocol commented Sep 17, 2012

Rebased, added decorators and a pile of tests.

6147e97...f95a03a

@jsocol jsocol closed this Sep 17, 2012
@rik
Copy link
Contributor Author

rik commented Sep 25, 2012

Thanks for filling in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants