SolarEdgeTech / pyctuator

Monitor Python applications using Spring Boot Admin
Apache License 2.0
175 stars 18 forks source link

FlaskPyctuator changes content types of unrelated requests when configured on root path "/" #108

Open vsutskever opened 6 months ago

vsutskever commented 6 months ago

If pyctuator is configured to start on "/" - it will modify content types of unrelated requests. A workaround is to initialize pyctuator in a sub path i.e /actuator

The culprit is likely therequest.path.startswith matching inside of FlaskPyctuator (And other adapters) middleware configuration. The

` @app.before_request def intercept_requests_and_responses() -> None: request_time = datetime.now()

        @after_this_request
        def after_response(response: Response) -> Response:
            response_time = datetime.now()

            # Set the SBA-V2 content type for responses from Pyctuator
            if request.path.startswith(self.pyctuator_impl.pyctuator_endpoint_path_prefix):
                **response.headers["Content-Type"] = SBA_V2_CONTENT_TYPE**

            # Record the request and response
            self.record_request_and_response(response, request_time, response_time)
            return response`