Skip to main content

Python library for GoReplay Middleware

Project description

Python library for GoReplay Middleware , API is quite similar to NodeJS library


To install GorMW, simply:

$ pip install gor

or from source:

python install

Getting Started

Initialize a AsyncioGor based middleware and start it in the following way:

from gor.middleware import AsyncioGor
proxy = AsyncioGor()

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

proxy = AsyncioGor()
proxy.on('request', on_request)

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. Have a try with the following command and sample middleware.

gor --input-raw :14000 --middleware "/path/to/" --output-http-track-response --input-raw-track-response --output-http ""
# coding: utf-8
import sys
from gor.middleware import AsyncioGor

def on_request(proxy, msg, **kwargs):
    proxy.on('response', on_response,, 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))
        sys.stderr.write('replay status is same as response status\n')

if __name__ == '__main__':
    proxy = AsyncioGor()
    proxy.on('request', on_request)


Since the release v0.2.x, Python2.7 and Python3.4 are not supported any more, the minimum supported Python version is 3.5.2. Besides the release v0.1.x is still compatible with Python2.7 and Python3.4.

Mutiple middleware choices

This library provides multiple middleware to choice, currently includes

  • AsyncioGor, implements based on python3 asyncio
  • MultiProcessGor, implements based multi processing

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for gor, version 0.2.3
Filename, size File type Python version Upload date Hashes
Filename, size gor-0.2.3-py3-none-any.whl (6.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size gor-0.2.3.tar.gz (5.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page