Index: grammalecte-server.py ================================================================== --- grammalecte-server.py +++ grammalecte-server.py @@ -182,14 +182,16 @@ @app.route("/get_options/fr") def listOptions (): "returns grammar options in a text JSON format" sUserId = request.cookies.user_id dOptions = dUser[sUserId]["gc_options"] if sUserId and sUserId in dUser else oGCE.getOptions() + response.set_header("Content-Type", "application/json; charset=UTF-8") return '{ "values": ' + json.dumps(dOptions, ensure_ascii=False) + ', "labels": ' + json.dumps(oGCE.getOptionsLabels("fr"), ensure_ascii=False) + ' }' @app.route("/suggest/fr/") def suggestGet (token): + response.set_header("Content-Type", "application/json; charset=UTF-8") try: xFuture = xProcessPoolExecutor.submit(suggest, token) return xFuture.result() except (concurrent.futures.TimeoutError, concurrent.futures.CancelledError): return '{"error": "Analysis aborted (time out or cancelled)"}' @@ -215,10 +217,11 @@ try: dUserOptions = dict(oGCE.getOptions()) if not dUserOptions else dict(dUserOptions) dUserOptions.update(json.loads(request.forms.options)) except (TypeError, json.JSONDecodeError): sError = "Request options not used." + response.set_header("Content-Type", "application/json; charset=UTF-8") try: xFuture = xProcessPoolExecutor.submit(parseText, request.forms.text, dUserOptions, bool(request.forms.tf), sError) return xFuture.result() except (concurrent.futures.TimeoutError, concurrent.futures.CancelledError): return '{"error": "Analysis aborted (time out or cancelled)"}' @@ -227,10 +230,11 @@ return '{"error": "Fatal error. The server failed."}' @app.route("/set_options/fr", method="POST") def setOptions (): "set grammar options for current user" + response.set_header("Content-Type", "application/json; charset=UTF-8") if request.forms.options: sUserId = request.cookies.user_id if request.cookies.user_id else next(userGenerator) dOptions = dUser[sUserId]["gc_options"] if sUserId in dUser else dict(oGCE.getOptions()) try: dOptions.update(json.loads(request.forms.options)) @@ -243,10 +247,11 @@ return '{"error": "No options received."}' @app.route("/reset_options/fr", method="POST") def resetOptions (): "default grammar options" + response.set_header("Content-Type", "application/json; charset=UTF-8") if request.cookies.user_id and request.cookies.user_id in dUser: try: del dUser[request.cookies.user_id] except KeyError: return '{"error" : "Unknown user."}' @@ -261,10 +266,11 @@ #def server_static (filepath): # return static_file(filepath, root='./views/static') @app.route("/suggest/fr", method="POST") def suggestPost (): + response.set_header("Content-Type", "application/json; charset=UTF-8") try: xFuture = xProcessPoolExecutor.submit(suggest, request.forms.token) return xFuture.result() except (concurrent.futures.TimeoutError, concurrent.futures.CancelledError): return '{"error": "Analysis aborted (time out or cancelled)"}'