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

def global_response_handler(response):
    response.headers["Access-Control-Allow-Origin"] = request.headers.get("Origin", "*")
    response.headers["Access-Control-Allow-Credentials"] = "true"
    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


def get_git_info():
    git_sha = Popen("git log -1 --oneline | awk '{ print $1 }'", stdout=PIPE, shell=True).communicate()[0].strip()
    git_branch = Popen("git rev-parse --abbrev-ref HEAD", stdout=PIPE, shell=True).communicate()[0].strip()
    return git_branch, git_sha


@app.route("/", methods=["GET"])
@app.route("/diag", methods=["GET"])
@app.route("/diagnostic", methods=["GET"])