Flask Snippets

Stream Proxy with Requests

By Zeray Rice filed in Utilities

# -*- coding: utf-8 -*-
    
from flask import Flask
from flask import Response
from flask import stream_with_context

import requests

app = Flask(__name__)

@app.route('/<path:url>')
def home(url):
    req = requests.get(url, stream = True)
    return Response(stream_with_context(req.iter_content()), content_type = req.headers['content-type'])

if __name__ == '__main__':
    app.run()

This snippet by Zeray Rice can be used freely for anything you like. Consider it public domain.