# HG changeset patch # User Kim Alvefur # Date 1579979079 -3600 # Node ID ede3d1724dd1fcfcbc82292a6a32d9426360e4a0 # Parent 9752a6f1b9f3a65672559b36162ee2d14422b7a9 mod_rest: Attempt to auto-discover data type wanted by callback diff -r 9752a6f1b9f3 -r ede3d1724dd1 mod_rest/example/app.py --- a/mod_rest/example/app.py Sat Jan 25 02:06:07 2020 +0100 +++ b/mod_rest/example/app.py Sat Jan 25 20:04:39 2020 +0100 @@ -3,6 +3,11 @@ app = Flask("echobot") +@app.route("/api", methods=["OPTIONS"]) +def options(): + return Response(status=200, headers={"accept": "application/json"}) + + @app.route("/api", methods=["POST"]) def hello(): print(request.data) diff -r 9752a6f1b9f3 -r ede3d1724dd1 mod_rest/mod_rest.lua --- a/mod_rest/mod_rest.lua Sat Jan 25 02:06:07 2020 +0100 +++ b/mod_rest/mod_rest.lua Sat Jan 25 20:04:39 2020 +0100 @@ -153,6 +153,15 @@ send_type = "application/json"; end + http.request(rest_url, { + method = "OPTIONS", + }, function (body, code, response) + if code == 200 and response.headers.accept then + send_type = decide_type(response.headers.accept); + module:log("debug", "Set 'rest_callback_content_type' = %q based on Accept header", send_type); + end + end); + local code2err = { [400] = { condition = "bad-request"; type = "modify" }; [401] = { condition = "not-authorized"; type = "auth" };