From 2615b8175f932624d5b556024b215922de8d60ba Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Mon, 13 Aug 2012 17:05:17 +0200 Subject: [PATCH] update the documentation about the web interface --- README.rst | 23 +++++++++++++++++++++++ vaurien/webserver.py | 7 +++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index cbb1245..a35f837 100644 --- a/README.rst +++ b/README.rst @@ -52,3 +52,26 @@ boolean that tels you if this is the communication to the proxied server or from it, name is the name of the callable, settings the settings for *this* callable and server the server instance (can be useful to look at the global settings for instance, and other utilities) + +Controlling vaurien from a web interface +======================================== + +Sometimes, it is useful to control how the proxy behaves, on a request to +request basis. Vaurien provides two proxies, the Random one that we defined +earlier and the OnTheFly one. + +The "on the fly" proxy comes with a simple http server to control itself. It +has two resources that could be useful to you: + + * `/handler [GET, POST]` which allows to either know what is the current + handler in use (when doing a `GET`) or to set a new one for the next + calls (`POST`). You can for instance do this with the following curl + call:: + + $ curl -d"delay" http://localhost:8080/handler -H "Content-Type: text/plain" + OK + + * `/handlers [GET]` returns a list of handlers that are possible to use:: + + $ curl http://localhost:8080/handlers -H "Content-Type: application/json" + {"handlers": ["delay", "errors", "hang", "blackout", "normal"]} diff --git a/vaurien/webserver.py b/vaurien/webserver.py index e1d4f69..224c5ee 100644 --- a/vaurien/webserver.py +++ b/vaurien/webserver.py @@ -1,5 +1,6 @@ """A simple, flask-based webserver able to control how the proxy behaves""" -from flask import Flask, request, request_started, request_finished +from flask import (Flask, request, request_started, request_finished, + make_response) import json app = Flask(__name__) @@ -22,7 +23,9 @@ def update_renderer(): @app.route('/handlers') def list_handlers(): """List all the available handlers""" - return json.dumps({'handlers': app.proxy.handlers.keys()}) + resp = make_response(json.dumps({'handlers': app.proxy.handlers.keys()})) + resp.content_type = 'application/json' + return resp # utils