Python library for GoReplay Middleware
Project description
Python library for GoReplay Middleware , API is quite similar to NodeJS library
Installation
To install GorMW, simply:
$ pip install gor
or from source:
python setup.py install
Getting Started
Initialize a TornadoGor based middleware and start it in the following way:
from gor.middleware import TornadoGor
proxy = TornadoGor()
proxy.run()
Basic idea is that you write callbacks which respond to request, response, replay, or message events, which contains request meta information and actuall http paylod. Depending on your needs you may compare, override or filter incoming requests and responses.
You can respond to the incoming events using on function, by providing callbacks:
def on_request(proxy, msg, **kwargs):
# do anything you want with msg
# msg is a GorMessage object
pass
proxy = TornadoGor()
proxy.on('request', on_request)
proxy.run()
You can provide request ID as additional argument to on function, which allow you to map related requests and responses. Below is example of middleware which checks that original and replayed response have same HTTP status code.
# coding: utf-8
import sys
from gor.middleware import TornadoGor
def on_request(proxy, msg, **kwargs):
proxy.on('response', on_response, idx=msg.id, req=msg)
def on_response(proxy, msg, **kwargs):
proxy.on('replay', on_replay, idx=kwargs['req'].id, req=kwargs['req'], resp=msg)
def on_replay(proxy, msg, **kwargs):
replay_status = proxy.http_status(msg.http)
resp_status = proxy.http_status(kwargs['resp'].http)
if replay_status != resp_status:
sys.stderr.write('replay status [%s] diffs from response status [%s]\n' % (replay_status, resp_status))
else:
sys.stderr.write('replay status is same as response status\n')
sys.stderr.flush()
if __name__ == '__main__':
proxy = TornadoGor()
proxy.on('request', on_request)
proxy.run()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gor-0.2.0.tar.gz.
File metadata
- Download URL: gor-0.2.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b05e88143b75611a3aad5a2fd291842ee60a348927c477e5fba90a670559f76
|
|
| MD5 |
17885290989e5a1428a4a05176a07866
|
|
| BLAKE2b-256 |
4dfd6a7393b3f15f64189b8763e1f3e8786d9979d645fe4ab8760f55c37c44b7
|
File details
Details for the file gor-0.2.0-py3-none-any.whl.
File metadata
- Download URL: gor-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9f3946fae9c369e14cffd4d916cbe2186ecf64192c4fb4104ec4101970a312c
|
|
| MD5 |
1a9d9f1314376145bac1240d2cecbf0e
|
|
| BLAKE2b-256 |
5673ae79163e1114e9493055c260cef4719b2575dc3911622a6511fd2a9b33d1
|