| 1 | <!-- |
| 2 | SPDX-License-Identifier: BSD-3-Clause |
| 3 | SPDX-FileCopyrightText: Czech Technical University in Prague |
| 4 | --> |
| 5 | |
| 6 | # http-relay |
| 7 | |
| 8 | Relay HTTP requests from localhost to a remote host (act as reverse HTTP proxy). |
| 9 | |
| 10 | This HTTP relay properly processes also the nonstandard HTTP responses like `ICY 200 OK` produced by Shoutcast or NTRIP streaming servers. |
| 11 | |
| 12 | The relay works properly with hostnames, IPv4 and IPv6 addresses. IPv6 addresses can be specified with or without `[]`. |
| 13 | |
| 14 | ## Usage |
| 15 | |
| 16 | ``` |
| 17 | usage: http-relay [-h] [-n NUM_THREADS] [-b BUFFER_SIZE] [-t SIGKILL_TIMEOUT] [-s] host [port] [local_port] [local_addr] |
| 18 | |
| 19 | positional arguments: |
| 20 | host The remote host to connect to (e.g. "cvut.cz") |
| 21 | port The remote host's port to connect to (e.g. 80). |
| 22 | local_port The local port to be used for the relay. If left out, will be the same as remote port. |
| 23 | local_addr Local interface (IP or hostname) to run the relay on. By default, it runs on all IPv4 interfaces (0.0.0.0). |
| 24 | |
| 25 | optional arguments: |
| 26 | -h, --help show this help message and exit |
| 27 | -n NUM_THREADS, --num-threads NUM_THREADS |
| 28 | Number of threads servicing the incoming requests. |
| 29 | -b BUFFER_SIZE, --buffer-size BUFFER_SIZE |
| 30 | Size of the buffer used for reading responses. Generally, a larger buffer should be more efficient, but if it is too large, the local clients may time out before they receive any data. |
| 31 | -t SIGKILL_TIMEOUT, --sigkill-timeout SIGKILL_TIMEOUT |
| 32 | If specified, the relay will be sigkilled in this number of seconds. |
| 33 | -s, --sigkill-on-stream-stop |
| 34 | If True, --sigkill-timeout will not be counted when no requests are active, and during requests, each successful data transmission will reset the timeout. This can be used to detect |
| 35 | stale streams if you expect an application to be constantly receiving data. |
| 36 | |
| 37 | ``` |
| 38 | |
| 39 | ## Python module |
| 40 | |
| 41 | This package also provides Python module `http_relay`. You can start the relay as a part of your application like this: |
| 42 | |
| 43 | ```python |
| 44 | from http_relay import run |
| 45 | |
| 46 | # ... |
| 47 | |
| 48 | run("0.0.0.0", 80, "cvut.cz", 80) |
| 49 | ``` |
| 50 | |
| 51 | ## Examples |
| 52 | |
| 53 | ```bash |
| 54 | http-relay cvut.cz 80 8080 # redirects local port 8080 to cvut.cz:80 |
| 55 | http-relay cvut.cz 2101 # redirects local port 2101 to cvut.cz:2101 |
| 56 | http-relay cvut.cz 80 8080 localhost # redirects localhost:8080 to cvut.cz:80 (i.e. no external access to the 8080 port) |
| 57 | |
| 58 | http-relay stream.cz 2101 -t 10 -s # redirects local port 2101 to stream.cz and kills the relay after 10 secs if a stream is being downloaded and becomes stale |
| 59 | ``` |