当前位置: 首页>>代码示例>>Python>>正文


Python request.is_secure方法代码示例

本文整理汇总了Python中flask.request.is_secure方法的典型用法代码示例。如果您正苦于以下问题:Python request.is_secure方法的具体用法?Python request.is_secure怎么用?Python request.is_secure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask.request的用法示例。


在下文中一共展示了request.is_secure方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: protect

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import is_secure [as 别名]
def protect(self):
        if request.method not in self._app.config['WTF_CSRF_METHODS']:
            return

        if not validate_csrf(self._get_csrf_token()):
            reason = 'CSRF token missing or incorrect.'
            return self._error_response(reason)

        if request.is_secure and self._app.config['WTF_CSRF_SSL_STRICT']:
            if not request.referrer:
                reason = 'Referrer checking failed - no Referrer.'
                return self._error_response(reason)

            good_referrer = 'https://%s/' % request.host
            if not same_origin(request.referrer, good_referrer):
                reason = 'Referrer checking failed - origin does not match.'
                return self._error_response(reason)

        request.csrf_valid = True  # mark this request is csrf valid 
开发者ID:jpush,项目名称:jbox,代码行数:21,代码来源:csrf.py

示例2: protect

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import is_secure [as 别名]
def protect(self):
        if request.method not in current_app.config['WTF_CSRF_METHODS']:
            return

        try:
            validate_csrf(self._get_csrf_token())
        except ValidationError as e:
            logger.info(e.args[0])
            self._error_response(e.args[0])

        if request.is_secure and current_app.config['WTF_CSRF_SSL_STRICT']:
            if not request.referrer:
                self._error_response('The referrer header is missing.')

            good_referrer = 'https://{0}/'.format(request.host)

            if not same_origin(request.referrer, good_referrer):
                self._error_response('The referrer does not match the host.')

        g.csrf_valid = True  # mark this request as CSRF valid 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:22,代码来源:csrf.py

示例3: nofollow_callback

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import is_secure [as 别名]
def nofollow_callback(attrs, new=False):
    """
    Turn relative links into external ones and avoid `nofollow` for us,

    otherwise add `nofollow`.
    That callback is not splitted in order to parse the URL only once.
    """

    if (None, 'href') not in attrs:
        return attrs
    parsed_url = urlparse(attrs[(None, 'href')])
    if parsed_url.netloc in ('', current_app.config['SERVER_NAME']):
        path = parsed_url.path
        attrs[(None, 'href')] = '{scheme}://{netloc}{path}'.format(
            scheme='https' if request.is_secure else 'http',
            netloc=current_app.config['SERVER_NAME'],
            path=path if path.startswith('/') else f'/{path}')
        return attrs
    else:
        rel = [x for x in attrs.get((None, 'rel'), '').split(' ') if x]
        if 'nofollow' not in [x.lower() for x in rel]:
            rel.append('nofollow')
        attrs[(None, 'rel')] = ' '.join(rel)
        return attrs 
开发者ID:opendatateam,项目名称:udata,代码行数:26,代码来源:markdown.py

示例4: redirect_to_ssl

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import is_secure [as 别名]
def redirect_to_ssl(self):
        """
        Redirect incoming requests to HTTPS.
        """
        criteria = [
            request.is_secure,
            current_app.debug,
            current_app.testing,
            request.headers.get("X-Forwarded-Proto", "http") == "https",
        ]

        if (
            request.headers.get("User-Agent", "")
            .lower()
            .startswith(self.exclude_user_agents)
        ):
            return

        if not any(criteria):
            if request.url.startswith("http://"):
                url = request.url.replace("http://", "https://", 1)
                r = redirect(url, code=301)
                return r 
开发者ID:getsentry,项目名称:zeus,代码行数:25,代码来源:ssl.py

示例5: gravatar

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import is_secure [as 别名]
def gravatar(self, size=100, default='identicon', rating='g'):
        if request.is_secure:
            url = 'https://secure.gravatar.com/avatar'
        else:
            url = 'http://www.gravatar.com/avatar'
        hash = self.avatar_hash or hashlib.md5(
            self.email.encode('utf-8')).hexdigest()
        return '{url}/{hash}?s={size}&d={default}&r={rating}'.format(
            url=url, hash=hash, size=size, default=default, rating=rating) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:11,代码来源:models.py

示例6: set_scheme

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import is_secure [as 别名]
def set_scheme(fn):
    @wraps(fn)
    def set_scheme_on_call(*args, **kwargs):
        scheme = 'https' if request.is_secure else 'http'
        current_app.config['SITEMAP_URL_SCHEME'] = scheme
        return fn(*args, **kwargs)
    return set_scheme_on_call 
开发者ID:opendatateam,项目名称:udata,代码行数:9,代码来源:sitemap.py

示例7: __init__

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import is_secure [as 别名]
def __init__(self, cookies=None, session=None, request_data=None, request_is_secure=None):
        self._cookies = request.cookies if cookies is None else cookies
        self.session = flask_session if session is None else session
        self._request_is_secure = request.is_secure if request_is_secure is None else request_is_secure

        if request_data:
            self._request_data = request_data 
开发者ID:dmitry-viskov,项目名称:pylti1.3,代码行数:9,代码来源:request.py

示例8: is_secure

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import is_secure [as 别名]
def is_secure(self):
        return self._request_is_secure 
开发者ID:dmitry-viskov,项目名称:pylti1.3,代码行数:4,代码来源:request.py

示例9: gravatar

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import is_secure [as 别名]
def gravatar(self, size=100, default='identicon', rating='g'):
        if request.is_secure:
            url = 'https://secure.gravatar.com/avatar'
        else:
            url = 'http://www.gravatar.com/avatar'
        hash = self.avatar_hash or \
               hashlib.md5(self.email.encode('utf-8')).hexdigest()
        return '{url}/{hash}?s={size}&d={default}&r={rating}'.format(
            url=url, hash=hash, size=size, default=default, rating=rating) 
开发者ID:miguelgrinberg,项目名称:flask-pycon2014,代码行数:11,代码来源:models.py

示例10: set_hsts_header

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import is_secure [as 别名]
def set_hsts_header(self, response):
        """
        Adds HSTS header to each response.
        """
        if request.is_secure:
            response.headers.setdefault("Strict-Transport-Security", self.hsts_header)
        return response 
开发者ID:getsentry,项目名称:zeus,代码行数:9,代码来源:ssl.py

示例11: log_in

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import is_secure [as 别名]
def log_in(self):
        response = flask.make_response()
        result = self.authomatic.login(
            WerkzeugAdapter(request, response),
            'google',
            session=session,
            session_saver=lambda: current_app.save_session(session, response),
            secure_cookie=(True if request.is_secure else False)
        )
        if result:
            if result.error:
                msg = 'Google auth failed with error: {0}'
                logger.error(msg.format(result.error))
                return abort(403)

            # successful login
            if result.user:
                result.user.update()
                user = result.user
                self.set_expiration()
                self.set_current_user(email=user.email,
                                      first_name=user.first_name,
                                      last_name=user.last_name)
                # TODO: find a way to save the angular args?
                # authomatic adds url params google auth has stripped the
                # angular args anyway, so let's just redirect back to the
                # index.
                resp = self.redirect_to_index()
                self.set_csrf_token(resp)
                return resp

        # Authomatic will have put a redirect in our response here.
        return response 
开发者ID:lyft,项目名称:confidant,代码行数:35,代码来源:userauth.py

示例12: _clean_url

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import is_secure [as 别名]
def _clean_url(self, url):
        if not url.startswith('http://') and not url.startswith('https://'):
            url = ('https://' if request.is_secure else 'http://') + url
        if not url.endswith('/'):
            url += '/'
        return url 
开发者ID:noirbizarre,项目名称:flask-fs,代码行数:8,代码来源:storage.py


注:本文中的flask.request.is_secure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。