HTTP tunnel over Websocket

WS PROXY

This is a reverse HTTP proxy over websockets. The aim is to securely make call to internal APIs from outside.

How does it works

a WSP client runs in the internal network ( alongside the APIs ) and connects to a remote WSP server with HTTP websockets.

One issue HTTP requests to the WSP server with an extra HTTP header 'X-PROXY-DESTINATION: "http://api.internal/resource"' to the /request endpoint.

The WSP Server then forward the request to the WSP Client over the one of the offered websockets. The WSP Client receive and execute locally an HTTP request to the URL provided in X-PROXY-DESTINATION and forwards the HTTP response back to the WSP server which in turn forwards the response back to the client. Please note that no buffering of any sort occurs.

If several WSP clients connect to a WSP server, requests will be spread in a random way to all the WSP clients.

wsp schema

Get code

go get github.com/root-gg/wsp

WSP server configuration

# wsp_server.cfg
---
host : 127.0.0.1                     # Address to bind the HTTP server
port : 8080                          # Port to bind the HTTP server
timeout : 1000                       # Time to wait before acquiring a WS connection to forward the request (milliseconds)
idletimeout : 60000                  # Time to wait before closing idle connection when there is enough idle connections (milliseconds)
#blacklist :                         # Forbidden destination ( deny nothing if empty )
# - method : ".*"                    #   Applied in order before whitelist
#   url : "^http(s)?://google.*"     #   None must match
#   headers :                        #   Optinal header check
#     X-CUSTOM-HEADER : "^value$"    # 
#whitelist :                         # Allowed destinations  ( allow all if empty )
# - method : "^GET$"                 #   Applied in order after blacklist
#   url : "^http(s)?://.*$"          #   One must match
#   headers :                        #   Optinal header check
#     X-CUSTOM-HEADER : "^value$"    # 
# secretkey : ThisIsASecret          # secret key that must be set in clients configuration
$ cd wsp_server && go build
$ ./wsp_server -config wsp_server.cfg
{
  "Host": "127.0.0.1",
  "Port": 8080
}
2016/11/22 15:31:39 Registering new connection from 7e2d8782-f893-4ff3-7e9d-299b4c0a518a
2016/11/22 15:31:40 Registering new connection from 7e2d8782-f893-4ff3-7e9d-299b4c0a518a
2016/11/22 15:31:40 Registering new connection from 7e2d8782-f893-4ff3-7e9d-299b4c0a518a
2016/11/22 15:31:40 Registering new connection from 7e2d8782-f893-4ff3-7e9d-299b4c0a518a
2016/11/22 15:31:40 Registering new connection from 7e2d8782-f893-4ff3-7e9d-299b4c0a518a
2016/11/22 15:31:40 Registering new connection from 7e2d8782-f893-4ff3-7e9d-299b4c0a518a
2016/11/22 15:31:40 Registering new connection from 7e2d8782-f893-4ff3-7e9d-299b4c0a518a
2016/11/22 15:31:40 Registering new connection from 7e2d8782-f893-4ff3-7e9d-299b4c0a518a
2016/11/22 15:31:40 Registering new connection from 7e2d8782-f893-4ff3-7e9d-299b4c0a518a
2016/11/22 15:31:40 Registering new connection from 7e2d8782-f893-4ff3-7e9d-299b4c0a518a
2016/11/22 15:33:34 GET map[User-Agent:[curl/7.26.0] Accept:[*/*] X-Proxy-Destination:[https://google.fr]]
2016/11/22 15:33:34 proxy request to 7e2d8782-f893-4ff3-7e9d-299b4c0a518a

For now TLS setup should be implemented using an HTTP reverse proxy like NGinx or Apache...

WSP proxy configuration

# wsp_client.cfg
---
targets :                            # Endpoints to connect to
 - ws://127.0.0.1:8080/register      #
poolidlesize : 10                    # Default number of concurrent open (TCP) connections to keep idle per WSP server
poolmaxsize : 100                    # Maximum number of concurrent open (TCP) connections per WSP server
#blacklist :                         # Forbidden destination ( deny nothing if empty )
# - method : ".*"                    #   Applied in order before whitelist
#   url : ".*forbidden.*"            #   None must match
#   headers :                        #   Optinal header check
#     X-CUSTOM-HEADER : "^value$"    # 
#whitelist :                         # Allowed destinations  ( allow all if empty )
# - method : "^GET$"                 #   Applied in order after blacklist
#   url : "http(s)?://.*$"           #   One must match
#   headers :                        #   Optinal header check
#     X-CUSTOM-HEADER : "^value$"    # 
# secretkey : ThisIsASecret          # secret key that must match the value set in servers configuration
  • poolMinSize is the default number of opened TCP/HTTP/WS connections to open per WSP server. If there is a burst of simpultaneous requests the number of open connection will rise and then decrease back to this number.
  • poolMinIdleSize is the number of connection to keep idle, meaning that if there is more than this number of simultaneous requests the WSP client will try to open more connections to keep idle connection.
  • poolMaxSize is the maximum number of simultaneous connection that the proxy will ever initiate per WSP server.
$ cd wsp_client && go build
$ ./wsp_client -config wsp_client.cfg
{
  "ID": "7e2d8782-f893-4ff3-7e9d-299b4c0a518a",
  "Targets": [
    "ws://127.0.0.1:8080/register"
  ],
  "PoolMinSize": 10,
  "PoolMinIdleSize": 5,
  "PoolMaxSize": 100
}
2016/11/22 15:31:39 Connecting to ws://127.0.0.1:8080/register
2016/11/22 15:31:40 Connecting to ws://127.0.0.1:8080/register
2016/11/22 15:31:40 Connecting to ws://127.0.0.1:8080/register
2016/11/22 15:31:40 Connecting to ws://127.0.0.1:8080/register
2016/11/22 15:31:40 Connecting to ws://127.0.0.1:8080/register
2016/11/22 15:31:40 Connecting to ws://127.0.0.1:8080/register
2016/11/22 15:31:40 Connecting to ws://127.0.0.1:8080/register
2016/11/22 15:31:40 Connecting to ws://127.0.0.1:8080/register
2016/11/22 15:31:40 Connecting to ws://127.0.0.1:8080/register
2016/11/22 15:31:40 Connecting to ws://127.0.0.1:8080/register
2016/11/22 15:33:34 got request : {"Method":"GET","URL":"https://google.fr","Header":{"Accept":["*/*"],"User-Agent":["curl/7.26.0"],"X-Proxy-Destination":["https://google.fr"]},"ContentLength":0}

Client

$ curl -H 'X-PROXY-DESTINATION: https://google.fr' http://127.0.0.1:8080/request
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="fr"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" it...
Similar Resources

A rule-based tunnel in Go with experimental features

A rule-based tunnel in Go with experimental features

Experimental-Clash A rule-based tunnel in Go with experimental features. Features Local HTTP/HTTPS/SOCKS server with authentication support VMess, Sha

Dec 25, 2022

An anonymous, encrypted Point-to-Point (Layer 3) tunnel between two peers.

NKN-Link An anonymous, encrypted Point-to-Point (Layer 3) tunnel between two peers. NKN-Link Table of Contents Preface Description Install Setup Run P

Dec 20, 2022

Gogrok is a self hosted, easy to use alternative to ngrok. It uses SSH as a base protocol, using channels and existing functionality to tunnel requests to an endpoint.

gogrok A simple, easy to use ngrok alternative (self hosted!) The server and client can also be easily embedded into your applications, see the 'serve

Dec 3, 2022

The devs are over here at devzat, chat over SSH!

Devzat Where are the devs at? Devzat! Devzat is chat over SSH Try it out: ssh sshchat.hackclub.com Add this to ~/.ssh/config: Host chat HostName s

Jan 7, 2023

开箱即用的基于命令的消息处理框架,让 websocket 和 tcp 开发就像 http 那样简单

Cmd Srv 开箱即用的基于命令的消息处理框架,让 websocket 和 tcp 开发就像 http 那样简单

Sep 25, 2022

HTTP, HTTP2, HTTPS, Websocket debugging proxy

HTTP, HTTP2, HTTPS, Websocket debugging proxy

English | 简体中文 We recommend updating whistle and Node to ensure that you receive important features, bugfixes and performance improvements. Some versi

Dec 31, 2022

NotifyTool - A message forwarding service for http to websocket

notifyTool this is a message forwarding service for http to websocket task webso

Jan 3, 2022

PlanB: a HTTP and websocket proxy backed by Redis and inspired by Hipache.

PlanB: a distributed HTTP and websocket proxy What Is It? PlanB is a HTTP and websocket proxy backed by Redis and inspired by Hipache. It aims to be f

Mar 20, 2022

A C/S Tool to Download Torrent Remotely and Retrieve Files Back Over HTTP at Full Speed without ISP Torrent Limitation.

remote-torrent Download Torrent Remotely and Retrieve Files Over HTTP at Full Speed without ISP Torrent Limitation. This repository is an extension to

Sep 30, 2022
Comments
  • add secret key needed for /register action

    add secret key needed for /register action

    This adds a secret key config setting that can be set in the server and client configs. When set, then only when the secret key matches in the server and client configurations will clients be allowed to register

GO Simple Tunnel - a simple tunnel written in golang
GO Simple Tunnel - a simple tunnel written in golang

GO Simple Tunnel GO语言实现的安全隧道 English README !!!V3版本已经可用,欢迎抢先体验!!! 特性 多端口监听 可设置转发代理,支持多级转发(代理链) 支持标准HTTP/HTTPS/HTTP2/SOCKS4(A)/SOCKS5代理协议 Web代理支持探测防御 支

Jan 2, 2023
Chisel is a fast TCP/UDP tunnel, transported over HTTP, secured via SSH.
Chisel is a fast TCP/UDP tunnel, transported over HTTP, secured via SSH.

Chisel is a fast TCP/UDP tunnel, transported over HTTP, secured via SSH. Single executable including both client and server. Written in Go (golang). Chisel is mainly useful for passing through firewalls, though it can also be used to provide a secure endpoint into your network.

Jan 1, 2023
Toy gRPC Tunnel over CloudFlare (Proof of Concept)
Toy gRPC Tunnel over CloudFlare (Proof of Concept)

gun You know what it means. Guide Server Go to your domain in CloudFlare. In "Network" tab, turn on gRPC.

Jan 6, 2023
TCP over HTTP/WebSocket

Introduction toh is tcp over http. short words: proxy your network over websocket Table of contents ToH server Caddy or Nginx wrap ToH server with TLS

May 6, 2023
Simple HTTP tunnel using SSH remote port forwarding

Simple HTTP tunnel using SSH remote port forwarding

Nov 18, 2022
A Stable & Secure Tunnel based on KCP with N:M multiplexing and FEC. Available for ARM, MIPS, 386 and AMD64。KCPプロトコルに基づく安全なトンネル。KCP 프로토콜을 기반으로 하는 보안 터널입니다。
A Stable & Secure Tunnel based on KCP with N:M multiplexing and FEC. Available for ARM, MIPS, 386 and AMD64。KCPプロトコルに基づく安全なトンネル。KCP 프로토콜을 기반으로 하는 보안 터널입니다。

Disclaimer: kcptun maintains a single website — github.com/xtaci/kcptun. Any websites other than github.com/xtaci/kcptun are not endorsed by xtaci. Re

Jan 9, 2023
Cloud Native Tunnel
Cloud Native Tunnel

inlets is a Cloud Native Tunnel written in Go Expose your local endpoints to the Internet or within a remote network, without touching firewalls. Foll

Jan 4, 2022
A deployable proxy server and tunnel written in go

Tunnelify Tunnelify is a deployable proxy server and tunnel written in go Installing | Quickstart | Configuration Installing Direct download You can i

Dec 11, 2022
Clash - A rule-based tunnel in Go.
Clash - A rule-based tunnel in Go.

Clash A rule-based tunnel in Go. Features Local HTTP/HTTPS/SOCKS server with authentication support VMess, Shadowsocks, Trojan, Snell protocol support

Jan 5, 2023