Skip to main content

Python library for GoReplay Middleware

Project description

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.

# 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()

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

gor-0.2.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gor-0.2.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file gor-0.2.1.tar.gz.

File metadata

  • Download URL: gor-0.2.1.tar.gz
  • Upload date:
  • Size: 4.5 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

Hashes for gor-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9711f3206c13551c7e71722f2e22e9b1c1f113f3c77e71aebfa15301d0787279
MD5 6229d7d059425efeb4a581149024bd5c
BLAKE2b-256 04ff432738783a2003e801b70d3a9594e91e519546e4eef1f5e16a0a0426fa38

See more details on using hashes here.

File details

Details for the file gor-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: gor-0.2.1-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

Hashes for gor-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 66ce00725848071de6b176def6e71a8e2071059c946a754bfa94ed5887f7eea3
MD5 f956c92b90fdea802631ff51cc50fcd3
BLAKE2b-256 8c7567c73e8d93e71464a63bb1237fd6eb28ef3c1b895fa38d333feaef2df517

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page