Flask Snippets

Snippets are unofficial and unmaintained.

This is an archived view of user-submitted snippets. Despite being hosted on the Flask site, they are not official. No Flask maintainer has curated or checked the snippets for security, correctness, or design.

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__)

@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.