pythonpython-3.xflaskweb-development-server

Flask passing another url through url variable


I'm trying to build a cors proxy through flask from scratch. Here's my code

@app.route('/api/v1/cors/url=<name>&method=<method>', methods=['GET'])
def api_cors(name, method):
    if method == 'http' or method == 'https':
        r = request.urlopen(method+"://"+name)
        return r.read()
    else:
        return "method not set!"

It is working good so far but I have one problem, when I pass "url=google.com&method=https" it is working fine but when I pass something like "url=google.com/images/image.jpg&method=https" the "/" will considered as a new directory

Is there anyway to evade this in flask?


Solution

  • If you want use the same URL scheme that you're using now, change your routing decorator to this and it will work.

    @app.route('/api/v1/cors/url=<path:name>&method=<method>', methods=['GET'])