merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 0217dadb0668f1f17d7b674181cc521a063dfca6
parent 6fa1d3108811820a111daaf442b094209bacfecb
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Fri, 28 Apr 2017 18:50:51 +0200

returning all the headers that the mitm got from
the exchange.  This copies the "server" headers though.
Wise?

Diffstat:
Msrc/mitm/talermerchantmitm/mitm.py | 20+++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/mitm/talermerchantmitm/mitm.py b/src/mitm/talermerchantmitm/mitm.py @@ -17,7 +17,8 @@ from flask import (request, Flask, - jsonify) + jsonify, + make_response) import requests from urllib.parse import (urljoin, urlencode, @@ -46,6 +47,12 @@ def track_transaction(resp): def track_transfer(resp): return resp +def fallback(resp): + if "application/json" == resp.headers["Content-Type"]: + return make_response(jsonify(resp.json())) + else: + return make_response(resp.text) + @app.route('/', defaults={'path': ''}) @app.route('/<path:path>', methods=["GET", "POST"]) def all(path): @@ -59,14 +66,13 @@ def all(path): r = requests.post(urljoin(url, path), json=body) else: r = requests.get(urljoin(url, path), json=body) - resp = dict() - if "application/json" == r.headers["Content-Type"]: - resp = r.json() dispatcher = { "track_transaction": track_transaction, "track_transfer": track_transfer } func = dispatcher.get(request.headers.get("X-Taler-Mitm"), - lambda x: x) - - return jsonify(func(resp)), r.status_code + fallback) + response = func(r) + for key, value in r.headers.items(): + response.headers[key] = value + return response, r.status_code