tornado-proxy-handlers

Tornado proxy handlers for HTTP requests and web sockets

https://dev.azure.com/tpaine154/miscellaneous/_apis/build/status/timkpaine.tornado-proxy-handlers?branchName=masterBuild Status https://img.shields.io/azure-devops/coverage/tpaine154/miscellaneous/29/masterCoverage https://img.shields.io/github/license/timkpaine/tornado-proxy-handlers.svgLicense https://img.shields.io/pypi/v/tornado-proxy-handlers.svgPyPI https://readthedocs.org/projects/tornado-proxy-handlers/badge/?version=latestDocs

Install

pip install tornado-proxy-handlers or from source python setup.py install

Overview

This project contains 2 proxy handlers:

  • HTTP Handler
  • Websocket Handler

The websocket handler requires the http handler for 599 protocol switching.

Use

These are designed to be embedded in a tornado server that needs to proxy. They can also be run as a standalone proxy server via the tornado-proxy command.

API Documentation

class tornado_proxy_handlers.handlers.ProxyHandler(application: tornado.web.Application, request: tornado.httputil.HTTPServerRequest, **kwargs)[source]

Bases: tornado.web.RequestHandler

get(url=None)[source]

Get the login page

initialize(proxy_url='/', **kwargs)[source]
class tornado_proxy_handlers.handlers.ProxyWSHandler(application: tornado.web.Application, request: tornado.httputil.HTTPServerRequest, **kwargs)[source]

Bases: tornado.websocket.WebSocketHandler

initialize(proxy_url='/', **kwargs)[source]
on_close()[source]

Invoked when the WebSocket is closed.

If the connection was closed cleanly and a status code or reason phrase was supplied, these values will be available as the attributes self.close_code and self.close_reason.

Changed in version 4.0: Added close_code and close_reason attributes.

on_message(message)[source]

Handle incoming messages on the WebSocket

This method must be overridden.

Changed in version 4.5: on_message can be a coroutine.

open(url=None)[source]

Invoked when a new WebSocket is opened.

The arguments to open are extracted from the tornado.web.URLSpec regular expression, just like the arguments to tornado.web.RequestHandler.get.

open may be a coroutine. on_message will not be called until open has returned.

Changed in version 5.1: open may be a coroutine.

tornado_proxy_handlers.server.main(proxy_url)[source]