mirror of
https://github.com/kennethreitz/httpbin.git
synced 2026-06-05 23:00:18 +00:00
First version of streaming support
This commit is contained in:
+15
-1
@@ -8,7 +8,7 @@ This module provides the core HttpBin experience.
|
||||
"""
|
||||
import os
|
||||
import time
|
||||
from flask import Flask, request, render_template, redirect, jsonify
|
||||
from flask import Flask, Response, request, render_template, redirect, jsonify
|
||||
from werkzeug.datastructures import WWWAuthenticate
|
||||
|
||||
|
||||
@@ -147,6 +147,20 @@ def relative_redirect_n_times(n):
|
||||
return response
|
||||
|
||||
|
||||
@app.route('/streaming/<int:n>')
|
||||
def http_streaming(n):
|
||||
"""Stream n messages"""
|
||||
def generate():
|
||||
for row in xrange(n):
|
||||
time.sleep(1)
|
||||
yield str(row) + "\n"
|
||||
|
||||
return Response(generate(), headers={
|
||||
"Transfer-Encoding": "chunked",
|
||||
"Content-Type": "application/json",
|
||||
})
|
||||
|
||||
|
||||
@app.route('/status/<int:code>')
|
||||
def view_status_code(code):
|
||||
"""Returns given status code."""
|
||||
|
||||
Reference in New Issue
Block a user