Created
December 15, 2010 16:14
-
-
Save jsdalton/742172 to your computer and use it in GitHub Desktop.
Simple http web test service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python test_server.py | |
# e.g GET http://127.0.0.1:5000/404 returns a 404 http response | |
# e.g. GET http://127.0.0.1:5000/200?sleep=10 returns a 200 after 10 seconds | |
import time | |
from flask import Flask, make_response, request | |
app = Flask(__name__) | |
@app.route('/<int:status_code>') | |
def return_status(status_code): | |
response = make_response() | |
response.status_code = status_code | |
response.data = response.status | |
sleep = request.args.get('sleep', None) | |
if sleep is not None: | |
time.sleep(int(sleep)) | |
return response | |
if __name__ == '__main__': | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment