Example #1
0
    def process_response(self, response):
        """Inject mimetype into response before it's sent to the WSGI server.

        This is only intended for stashable view functions, created by
        :meth:`Tango.build_view`.
        """
        Flask.process_response(self, response)
        ctx = _request_ctx_stack.top
        if hasattr(ctx, 'mimetype'):
            mimetype, charset = (ctx.mimetype, response.charset)
            response.content_type = get_content_type(mimetype, charset)
            response.headers['Content-Type'] = response.content_type
        return response
Example #2
0
    return (
        response_string,
        status_code,
        {"Content-Type": content_type, "Cache-Control": "no-cache", "Pragma": "no-cache"}
    )

def global_response_handler(response):
    response.headers['X-HOSTNAME'] = app.config['X-HOSTNAME']
    response.headers['X-APP-VERSION'] = app.config['VERSION']
    return response

def global_request_handler():
    # this needs to be safe for use by the app
    g.user_token = secure_filename(request.headers.get(app.config['USER_HEADER_NAME'], 'DEFAULT'))

app.process_response = global_response_handler    
app.preprocess_request = global_request_handler

################################################################################
# views 

@app.route("/", methods=["GET"])
@app.route("/diagnostic", methods=["GET"])
@make_my_response_json
def pyserver_core_diagnostic_view():
    """
        Used to return the status of the application, including the version
        of the running application.
    
        :statuscode 200: returned as long as all checks return healthy
        :statuscode 500: returned in the case of any diagnostic tests failing