Flask Snippets

Stream Proxy with Requests

Posted by Zeray Rice on 2013-11-15 @ 19:19 and 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__)

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__':

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