Python flask.request.scheme() Examples
The following are 22
code examples of flask.request.scheme().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask.request
, or try the search function
.
Example #1
Source File: saml.py From InfraBox with Apache License 2.0 | 5 votes |
def init_saml_auth(): parsed_url = urlparse(request.url) request_data = { "https": "on" if request.scheme == "https" else "off", "http_host": request.host, "server_port": parsed_url.port, "script_name": request.path, "get_data": request.args.copy(), "post_data": request.form.copy(), "query_string": request.query_string } auth = OneLogin_Saml2_Auth(request_data, custom_base_path=get_env("INFRABOX_ACCOUNT_SAML_SETTINGS_PATH")) return auth
Example #2
Source File: Dr0p1t_Server.py From Dr0p1t-Framework with MIT License | 5 votes |
def exceptions(e): tb = traceback.format_exc() timestamp = strftime('[%Y-%b-%d %H:%M]') f = open("server.log","a").write( "\n"+"--"*10+"\n"+'%s %s %s %s %s 5xx INTERNAL SERVER ERROR\n%s'%(timestamp, request.remote_addr, request.method, request.scheme, request.full_path, tb) ) return abort(500)
Example #3
Source File: Dr0p1t_Server.py From Dr0p1t-Framework with MIT License | 5 votes |
def after_request(response): timestamp = strftime('[%Y-%b-%d %H:%M]') f = open("server.log","a").write( "\n"+"--"*10+"\n"+'%s %s %s %s %s %s'%(timestamp, request.remote_addr, request.method, request.scheme, request.full_path, response.status) ) return response
Example #4
Source File: redirects.py From incubator-superset with Apache License 2.0 | 5 votes |
def shortner(self) -> FlaskResponse: # pylint: disable=no-self-use url = request.form.get("data") obj = models.Url(url=url) db.session.add(obj) db.session.commit() return Response( "{scheme}://{request.headers[Host]}/r/{obj.id}".format( scheme=request.scheme, request=request, obj=obj ), mimetype="text/plain", )
Example #5
Source File: __init__.py From capybara.py with MIT License | 5 votes |
def host(): return "Current host is {0}://{1}".format(request.scheme, request.host)
Example #6
Source File: root.py From cloudkitty with Apache License 2.0 | 5 votes |
def get_api_versions(): """Returns a list of all existing API versions.""" apis = [ { 'id': 'v1', 'links': [{ 'href': '{scheme}://{host}/v1'.format( scheme=request.scheme, host=request.host, ), }], 'status': 'CURRENT', }, { 'id': 'v2', 'links': [{ 'href': '{scheme}://{host}/v2'.format( scheme=request.scheme, host=request.host, ), }], 'status': 'EXPERIMENTAL', }, ] # v2 api is disabled when using v1 storage if CONF.storage.version < 2: apis = apis[:1] return apis
Example #7
Source File: app.py From SnowAlert with Apache License 2.0 | 5 votes |
def error_handler(ex): logger.exception( 'An error has occurred! ({} {} {} {})'.format( request.remote_addr, request.method, request.scheme, request.full_path ) ) return 'Internal Server Error', 500
Example #8
Source File: WebApp.py From AIOPS_PLATFORM with MIT License | 5 votes |
def exceptions(e): """ Logging after every Exception. """ ts = strftime('[%Y-%b-%d %H:%M]') logger.error('%s %s %s %s %s 5xx INTERNAL SERVER ERROR', ts, request.remote_addr, request.method, request.scheme, request.full_path) return("Internal Server Error", 500)
Example #9
Source File: WebApp.py From AIOPS_PLATFORM with MIT License | 5 votes |
def after_request(response): if response.status_code != 500: ts = strftime('[%Y-%b-%d %H:%M]') logger.info('%s %s %s %s %s %s', ts, request.remote_addr, request.method, request.scheme, request.full_path, response.status) return(response)
Example #10
Source File: flask_gopher.py From flask-gopher with GNU General Public License v3.0 | 5 votes |
def _add_gopher_error_handler(self, app): """ Intercept all errors for GOPHER requests and replace the default HTML error document with a gopher compatible text document. """ def handle_error(error): if request.scheme != 'gopher': # Pass through the error to the default handler return error code = getattr(error, 'code', 500) name = getattr(error, 'name', 'Internal Server Error') desc = getattr(error, 'description', None) if desc is None and self.show_stack_trace: desc = traceback.format_exc() elif desc is None: desc = 'An internal error has occurred' body = [menu.error(code, name), '', self.formatter.wrap(desc)] # There's no way to know if the client has requested a gopher # menu, a text file, or a binary file. But we can make a guess # based on if the request path has a file extension at the end. ext = os.path.splitext(request.path)[1] if ext: return '\r\n'.join(body) else: return self.render_menu(*body) # Attach this handler to all of the builtin flask exceptions for cls in HTTPException.__subclasses__(): app.register_error_handler(cls, handle_error)
Example #11
Source File: __init__.py From cloud-inquisitor with Apache License 2.0 | 5 votes |
def _prepare_flask_request(): # If server is behind proxys or balancers use the HTTP_X_FORWARDED fields url_data = urlparse(request.url) port = url_data.port or (443 if request.scheme == 'https' else 80) return { 'https': 'on' if request.scheme == 'https' else 'off', 'http_host': request.host, 'server_port': port, 'script_name': request.path, 'get_data': request.args.copy(), 'post_data': request.form.copy() }
Example #12
Source File: manager.py From cloudify-manager with Apache License 2.0 | 5 votes |
def _is_enabled(): return request.scheme == 'https'
Example #13
Source File: entrypoint.py From renku-python with Apache License 2.0 | 5 votes |
def exceptions(e): """App exception logger.""" tb = traceback.format_exc() service_log.error( '{} {} {} {} 5xx INTERNAL SERVER ERROR\n{}'.format( request.remote_addr, request.method, request.scheme, request.full_path, tb ) ) return e.status_code
Example #14
Source File: entrypoint.py From renku-python with Apache License 2.0 | 5 votes |
def after_request(response): """After request handler.""" service_log.info( '{0} {1} {2} {3} {4}'.format( request.remote_addr, request.method, request.scheme, request.full_path, response.status ) ) return response
Example #15
Source File: api.py From nekoyume with MIT License | 5 votes |
def post_move(): new_move = request.get_json() move = Move.query.get(new_move['id']) if move: return jsonify(result='success') if not move: move = Move.deserialize(new_move) if not move.valid: return jsonify(result='failed', message=f"move {move.id} isn't valid."), 400 db.session.add(move) try: db.session.commit() except IntegrityError: return jsonify(result='failed', message="This node already has this move."), 400 sent_node = Node() if 'sent_node' in new_move: sent_node.url = new_move['sent_node'] move_broadcast.delay( move.id, sent_node_url=sent_node.url, my_node_url=f'{request.scheme}://{request.host}' ) return jsonify(result='success')
Example #16
Source File: assets.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def from_manifest(app, filename, raw=False, **kwargs): ''' Get the path to a static file for a given app entry of a given type. :param str app: The application key to which is tied this manifest :param str filename: the original filename (without hash) :param bool raw: if True, doesn't add prefix to the manifest :return: the resolved file path from manifest :rtype: str ''' cfg = current_app.config if current_app.config.get('TESTING'): return # Do not spend time here when testing path = _manifests[app][filename] if not raw and cfg.get('CDN_DOMAIN') and not cfg.get('CDN_DEBUG'): scheme = 'https' if cfg.get('CDN_HTTPS') else request.scheme prefix = '{}://'.format(scheme) if not path.startswith('/'): # CDN_DOMAIN has no trailing slash path = '/' + path return ''.join((prefix, cfg['CDN_DOMAIN'], path)) elif not raw and kwargs.get('external', False): if path.startswith('/'): # request.host_url has a trailing slash path = path[1:] return ''.join((request.host_url, path)) return path
Example #17
Source File: __init__.py From hellogithub.com with GNU Affero General Public License v3.0 | 5 votes |
def exceptions(e): tb = traceback.format_exc() tb = tb.decode('utf-8') logger.error('%s %s %s %s 5xx INTERNAL SERVER ERROR\n%s', request.environ.get('HTTP_X_REAL_IP', request.remote_addr), request.method, request.scheme, request.full_path, tb) return '500 INTERNAL SERVER ERROR', 500
Example #18
Source File: __init__.py From hellogithub.com with GNU Affero General Public License v3.0 | 5 votes |
def after_request(response): logger.info('%s %s %s %s %s', request.method, request.environ.get('HTTP_X_REAL_IP', request.remote_addr), request.scheme, request.full_path, response.status) return response
Example #19
Source File: app.py From shorty with MIT License | 5 votes |
def exceptions(e): tb = traceback.format_exc() timestamp = strftime('[%Y-%b-%d %H:%M]') logger.error('%s %s %s %s %s 5xx INTERNAL SERVER ERROR\n%s', timestamp, request.remote_addr, request.method, request.scheme, request.full_path, tb) return make_response(e , 405)
Example #20
Source File: app.py From shorty with MIT License | 5 votes |
def after_request(response): timestamp = strftime('[%Y-%b-%d %H:%M]') logger.error('%s %s %s %s %s %s',timestamp , request.remote_addr , \ request.method , request.scheme , request.full_path , response.status) return response
Example #21
Source File: flask_gopher.py From flask-gopher with GNU General Public License v3.0 | 4 votes |
def save_session(self, app, session, response): """ Normally the session is saved by adding a cookie header to the response object. However, in this case, because were using a query param we need to insert the session into every internal link that's returned in the response body. Unfortunately there's no easy way to do this, so for now I'm using a regex search that looks for gopher internal menu links and appends the _session query param to the end of each link selector. """ if not session or response.direct_passthrough: # Don't bother trying to save the session if there's nothing to save, # or if the response is a static file or streaming file. return None s = self.get_gopher_signing_serializer(app) session_str = s.dumps(dict(session)) # Build the regex pattern that searches for internal gopher menu links host = request.environ['SERVER_NAME'] port = request.environ['SERVER_PORT'] url_pattern = '^(?P<type>[^i])(?P<desc>.+)\t(?P<selector>.*)\t%s\t%s\r$' url_pattern = url_pattern % (re.escape(host), re.escape(port)) def on_match(matchobj): """ This function is called on every regex match. It takes an existing gopher link, extracts the path and the query string, adds the _session param to it, and rebuilds the link. """ url_parts = urlsplit(matchobj.group('selector')) query = parse_qs(url_parts.query) query['_session'] = [session_str] new_query = urlencode(query, doseq=True) new_url = urlunsplit([ url_parts.scheme, url_parts.netloc, url_parts.path, new_query, url_parts.fragment]) new_line = '%s%s\t%s\t%s\t%s\r' % ( matchobj.group('type'), matchobj.group('desc'), new_url, host, port) return new_line data = bytes.decode(response.data) new_data = re.sub(url_pattern, on_match, data, flags=re.M) response.data = new_data.encode()
Example #22
Source File: api.py From nekoyume with MIT License | 4 votes |
def post_block(): new_block = request.get_json() last_block = Block.query.order_by(Block.id.desc()).first() if not new_block: return jsonify(result='failed', message="empty block."), 400 if not last_block and new_block['id'] != 1: Block.sync( Node.query.order_by( Node.last_connected_at.desc()).first()) return jsonify(result='failed', message="new block isn't our next block."), 403 if (new_block['id'] > 1 and (new_block['id'] != last_block.id + 1 or new_block['prev_hash'] != last_block.hash)): if new_block['id'] > last_block.id + 1: Block.sync( Node.query.order_by( Node.last_connected_at.desc()).first()) return jsonify(result='failed', block_id=last_block.id, message="new block isn't our next block."), 403 block = Block.deserialize(new_block) for new_move in new_block['moves']: move = Move.query.get(new_move['id']) if not move: Move.deserialize(new_move, block.id) if not move.valid: return jsonify(result='failed', message=f"move {move.id} isn't valid."), 400 block.moves.append(move) if not block.valid: return jsonify(result='failed', message="new block isn't valid."), 400 db.session.add(block) try: db.session.commit() except IntegrityError: return jsonify(result='failed', message="This node already has this block."), 400 sent_node = Node() if 'sent_node' in new_block: sent_node.url = new_block['sent_node'] block_broadcast.delay( block.id, sent_node_url=sent_node.url, my_node_url=f'{request.scheme}://{request.host}' ) return jsonify(result='success')