Skip to content

Commit

Permalink
update the documentation about the web interface
Browse files Browse the repository at this point in the history
  • Loading branch information
almet committed Aug 13, 2012
1 parent 7502fe1 commit 2615b81
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
23 changes: 23 additions & 0 deletions README.rst
Expand Up @@ -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"]}
7 changes: 5 additions & 2 deletions 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__)
Expand All @@ -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
Expand Down

0 comments on commit 2615b81

Please sign in to comment.