Danangjoyoo / flask-http-middleware

Flask HTTP Middleware with starlette's (FastAPI) BaseHTTPMiddleware style
MIT License
12 stars 1 forks source link

Silent failure with Flask 2.3.X #7

Closed Vishengel closed 10 months ago

Vishengel commented 12 months ago

Hi again @Danangjoyoo,

When using Flask 2.3.X, any middleware added simply does not work, without any error. It seems like the middleware's dispatch() function is not being called altogether. On my side, this can be reproduced by running your example code with Flask 2.3.X installed:

import time
from flask import Flask
from flask_http_middleware import MiddlewareManager, BaseHTTPMiddleware

app = Flask(__name__)

class MetricsMiddleware(BaseHTTPMiddleware):
    def __init__(self):
        super().__init__()

    def dispatch(self, request, call_next):
        t0 = time.time()
        response = call_next(request)
        response_time = time.time()-t0
        response.headers.add("response_time", response_time)
        return response

app.wsgi_app = MiddlewareManager(app)
app.wsgi_app.add_middleware(MetricsMiddleware)

@app.get("/health")
def health():
    return {"message":"I'm healthy"}

if __name__ == "__main__":
    app.run()

With Flask 2.3.X, dispatch() is never called, while with Flask 2.2.X it is.

Danangjoyoo commented 11 months ago

Hi @Vishengel thanks again for reporting me this issue, I will check this and fixed it soon!

Danangjoyoo commented 11 months ago

Hi @Vishengel I have updated the package and test it along with #6 . Now it works as expected, please check it~

Danangjoyoo commented 11 months ago

Hi, I've just fixed this, kindly update to 0.4.1 🙇