From 79babdf4218657343649fbdb7776d5897a9c4719 Mon Sep 17 00:00:00 2001 From: Taka Date: Thu, 4 Feb 2021 22:42:42 +1100 Subject: [PATCH] Fixed a problem with how we serve some counter images. --- vasl_templates/webapp/files.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/vasl_templates/webapp/files.py b/vasl_templates/webapp/files.py index bda0280..377ce29 100644 --- a/vasl_templates/webapp/files.py +++ b/vasl_templates/webapp/files.py @@ -72,9 +72,17 @@ def get_user_file( path ): # --------------------------------------------------------------------- +# FUDGE! We had a weird problem here after upgrading to Flask 1.1.2. We used the "defaults" parameter +# to set a default value of 0 for the "index" parameter, but if the caller explicitly passed in a value of 0, +# I think Flask was trying to be clever and returning a HTTP 308 Permanent Redirect to the other path e.g. +# /counter/12345/front/0 => HTTP 308 /counter/12345/front +# which is fine, except that VASSAL doesn't understand HTTP 308's >:-/ Oddly, it was only happening here, +# and not at other places where we have default parameters (maybe because we're using send_file()?). +# We work-around this by changing how we specify the default value for "index". Sigh... + @app.route( "/counter///" ) -@app.route( "/counter//", defaults={"index":0} ) -def get_counter_image( gpid, side, index ): +@app.route( "/counter//" ) +def get_counter_image( gpid, side, index=0 ): """Get a counter image.""" # check if a VASL module has been configured @@ -87,7 +95,7 @@ def get_counter_image( gpid, side, index ): abort( 404 ) return send_file( io.BytesIO( image_data ), - attachment_filename = os.path.split( image_path )[1]## nb: so Flask can figure out the MIME type + attachment_filename = os.path.split( image_path )[1] # nb: so Flask can figure out the MIME type ) # ---------------------------------------------------------------------