Skip to main content

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

https://badge.fury.io/py/gor.svg https://travis-ci.org/amyangfei/GorMW.svg?branch=master https://coveralls.io/repos/github/amyangfei/GorMW/badge.svg?branch=master

Installation

To install GorMW, simply:

$ pip install gor

or from source:

python setup.py install

Getting Started

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

from gor.middleware import AsyncioGor
proxy = AsyncioGor()
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 = AsyncioGor()
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. Have a try with the following command and sample middleware.

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


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 = AsyncioGor()
    proxy.on('request', on_request)
    proxy.run()

Mutiple middleware choices

This library provides multiple middleware to choice, currently includes

  • AsyncioGor, implements based on python3 asyncio

  • MultiProcessGor, implements based multi processing

Metadata

Release files for gor 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gor 0.2.3
File Size Uploaded
gor-0.2.3.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gor 0.2.3
File Interpreter ABI Platform
gor-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / gor-0.2.3.tar.gz

Download URL gor-0.2.3.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
78b66b34919be4e3e8da3d67044305aae7ef919d68b99509d65624f1078acc20
BLAKE2b-256 checksum
How to use checksums
9ba81b7b4a6649f58a2d8b451daad9c671bee635ceedb4eedebe4ec3e25e1000
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

Release files / gor-0.2.3-py3-none-any.whl

Download URL gor-0.2.3-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8aabda9e174bff1c33fce32fe4fd4280c72ea98cf67f598337f645c4689d7a20
BLAKE2b-256 checksum
How to use checksums
f0d74e91e32fe4eea5a7ae69504a579c6dc0747f40aca220ceb9f6b761ab1551
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page