diff --git a/README.md b/README.md index bfe725a..7644d9d 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ Freely hosted in [HTTP](http://httpbin.org) & - [`/basic-auth/:user/:passwd`](http://httpbin.org/basic-auth/user/passwd) Challenges HTTPBasic Auth. - [`/hidden-basic-auth/:user/:passwd`](http://httpbin.org/hidden-basic-auth/user/passwd) 404'd BasicAuth. - [`/digest-auth/:qop/:user/:passwd`](http://httpbin.org/digest-auth/auth/user/passwd) Challenges HTTP Digest Auth. -- [`/stream/:n`](http://httpbin.org/stream/100) Streams *n* lines. -- [`/delay/:n`](/delay/3) Delays responding for *n* seconds. +- [`/stream/:n`](http://httpbin.org/stream/20) Streams *n*–100 lines. +- [`/delay/:n`](/delay/3) Delays responding for *n*–10 seconds. ## DESCRIPTION diff --git a/httpbin/core.py b/httpbin/core.py index 5560eec..04b42fa 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -153,11 +153,12 @@ def relative_redirect_n_times(n): def stream_n_messages(n): """Stream n JSON messages""" response = get_dict('url', 'args', 'headers', 'origin') + n = min(n, 100) def generate_stream(): for i in range(n): - response["id"] = i - yield json.dumps(response) + "\n" + response['id'] = i + yield json.dumps(response) + '\n' return Response(generate_stream(), headers={ "Transfer-Encoding": "chunked", @@ -190,9 +191,10 @@ def view_status_code(codes): @app.route('/response-headers') def response_headers(): - """ Returns a set of response headers from the query string """ + """Returns a set of response headers from the query string """ headers = CaseInsensitiveDict(request.args.items()) response = jsonify(headers.items()) + while True: content_len_shown = response.headers['Content-Length'] response = jsonify(response.headers.items()) @@ -276,11 +278,13 @@ def digest_auth(qop=None, user='user', passwd='passwd'): def delay_response(delay): """Returns a delayed response""" delay = min(delay, 10) + time.sleep(delay) return jsonify(get_dict( 'url', 'args', 'form', 'data', 'origin', 'headers', 'files')) + @app.route('/base64/') def decode_base64(value): """Decodes base64url-encoded string""" diff --git a/httpbin/templates/httpbin.1.html b/httpbin/templates/httpbin.1.html index cc0bbf7..cf21dae 100644 --- a/httpbin/templates/httpbin.1.html +++ b/httpbin/templates/httpbin.1.html @@ -24,8 +24,8 @@
  • /basic-auth/:user/:passwd Challenges HTTPBasic Auth.
  • /hidden-basic-auth/:user/:passwd 404'd BasicAuth.
  • /digest-auth/:qop/:user/:passwd Challenges HTTP Digest Auth.
  • -
  • /stream/:n Streams n lines.
  • -
  • /delay/:n Delays responding for n seconds.
  • +
  • /stream/:n Streams n–100 lines.
  • +
  • /delay/:n Delays responding for n–10 seconds.