2

I am running a Flask API with multiple blueprints registered to it, but I want to limit the content length with different sizes for different blueprints.

I want to do something similar to "app.config["MAX_CONTENT_LENGTH"] = 1024" but for each Blueprint rather than the entire app. I read somewhere that you can do request.content_length, but I'm not sure if that is doing the same thing. My end goal is to determine the size without having to load the data into memory. Are there any complications or differences between using request.content_length to check for size vs how flask does it internally with app.config["MAX_CONTENT_LENGTH"]?

rjr862
  • 51
  • 5
  • Related: http://stackoverflow.com/questions/25036498/is-it-possible-to-limit-flask-post-data-size-on-a-per-route-basis - check out the decorator they implement in this post. – Kyle Pittman Oct 06 '15 at 18:51
  • Yes thanks, this is the post I was referring to when I said "I read somewhere you can do request.content_length." I guess my main question was, is this poster's comment a valid statement: "This is essentially what Flask does". Does Flask simply use the same internal logic as request.content_length? And if so, what if content_length is not a property provided by the request? – rjr862 Oct 06 '15 at 19:41
  • I checked the flask source on github and I could not find the code where the logic for checking `request.content_length` and comparing it to `MAX_CONTENT_LENGTH` was implemented, so I can't say how it's all handled. – Kyle Pittman Oct 06 '15 at 19:47
  • 1
    I'm wondering if flask has the ability to stop reading data from the client connection after its exceeded a content length limit or does all the data pass through the connection regardless – rjr862 Oct 06 '15 at 20:12
  • And when I checked out the [flask source](https://github.com/mitsuhiko/flask) to answer that question, I am unable to find where flask handles this logic at all. Perhaps it's taken care of in [Werkzeug's formparser (line 184)](https://github.com/mitsuhiko/werkzeug/blob/d4e8b3f46c51e7374388791282e66323f64b3068/werkzeug/formparser.py#L184) and not flask at all. – Kyle Pittman Oct 06 '15 at 20:22

0 Answers0