A service to proxy requests to a given backend service.

Proxy Service

A service to proxy requests to a given backend service.


Go 1.17+

Clone

git clone [email protected]:janu-cambrelen/proxy-service.git

Run (Local)

Run either of the following from the same directory as this README (change values as needed).

With Flags

go run main.go \
-debug=true \
-host=localhost \
-port=8080 \
-target-url=http://jsonplaceholder.typicode.com/ \
-body-methods-only=true \
-reject-with=bad_message \
-reject-exact=true \
-reject-insensitive=false \
-request-delay=2

With .env File

echo \
'DEBUG=true
HOST="localhost"
PORT=8080
TARGET_URL=http://jsonplaceholder.typicode.com/
BODY_METHODS_ONLY=true
REJECT_WITH=bad_message
REJECT_EXACT=true
REJECT_INSENSITIVE=false
REQUEST_DELAY=2' > .env
go run main.go

Overview / Usage

Target URL:

The target backend "service" is set using the TARGET_URL environment file setting or by the -target-url CLI flag. The server will fail to initialize if the target url is not provided.

If, for example, we wanted to hit the http://backend-service.com/user endpoint of our backend service we would set http://backend-service.com/ as our target URL.

The proxy server will handle routing and map the URI accordingly. Therefore, to hit the /user endpoint from the proxy server, the request should be made to http://proxy-service.com/user.


Supported HTTP Methods and Content-Type:

This service only accepts POST, PUT, and PATCH requests if the BODY_METHODS_ONLY environment file setting or the body-methods-only CLI flag is set to true. Otherwise, this service is able to support other methods (including GET requests with query params etc.).

Also, all requests and responses should be of content type application/json.

The client will receive an error, detailing the issue, if the aforementioned is not conformed to.


Request Filtering:

This service can reject requests from ever reaching the backend / target based on a specfied word or phrase contained within the REJECT_WITH environment file setting or by the reject-with CLI flag.

Whether this validation is concerned with an "exact" match or "contains" match determined by the REJECT_EXACT environment file setting or by the reject-exact CLI flag.

Finally, whether this check is case-sensitve is determined by the REJECT_INSENSITIVE environment file setting or by the reject-insensitive CLI flag.


Consecutive Request Delay:

The service will delay its response by two seconds if consective requests, containing the same content (i.e., request body) and common set of headers, are received.

The delay can be changed via the REQUEST_DELAY environment file setting or by the -request-delay CLI flag. Only positive integer values are supported.

The server will fail to initialize if the request delay is negative; otherwise, if not set, it will fault to two seconds.


Sample Backend Service: https://jsonplaceholder.typicode.com/

Sample Request (successful)

curl --location --include --request PATCH 'http://localhost:8080/posts/1' \
--header 'Content-Type: application/json' \
--data-raw '{
    "body": "good_message"
}'

Sample Response (successful)

HTTP/1.1 200 OK
Content-Type: application/json
X-Proxy-Request-Id: 6ad80a7c-c132-4417-8323-fdfcaf7365e8
Date: Tue, 14 Dec 2021 02:06:27 GMT
Content-Length: 138

{
  "userId": 1,
  "id": 1,
  "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
  "body": "good_message"
}

Sample Request (unsuccessful)

curl --location --include --request PATCH 'http://localhost:8080/posts/1' \
--header 'Content-Type: application/json' \
--data-raw '{
    "body": "bad_message"
}'

Sample Response (unsuccessful)

HTTP/1.1 401 Unauthorized
Content-Length: 62
Content-Type: application/json
Date: Tue, 14 Dec 2021 02:08:21 GMT

{"code":"401","msg":"rejected because `bad_message` found within request body"}

Test

Unit Tests

go test ./internal/proxyserver -v 

End-to-End Tests

bash scripts/e2e.sh

or

./scripts/e2e.sh 

All

go test ./internal/proxyserver -v && ./scripts/e2e.sh 

NOTE: May need to chmod +x ./scripts/e2e.sh if you encounter permissions issue.


Docs

Update documentation within the doc directory:

go doc --all cmd  > doc/cmd.txt 
go doc --all internal/proxyserver > doc/proxyserver.txt

TODO

  • Dockerize
  • Deploy Scripts / Makefile
  • Precommit Hooks (e.g., go mod tidy, docs)
  • Test Coverage
Owner
Similar Resources

An experimental Tor-Proxy serivce written in Go using Go-proxy and Go-libtor.

tor-proxy An experimental standalone tor-proxy service built with Go, using go-proxy, go-libtor and bine. This is a simple replacement to Tor's origin

Nov 9, 2022

mt-multiserver-proxy is a reverse proxy designed for linking multiple Minetest servers together

mt-multiserver-proxy mt-multiserver-proxy is a reverse proxy designed for linking multiple Minetest servers together. It is the successor to multiserv

Nov 17, 2022

A simple tool to convert socket5 proxy protocol to http proxy protocol

Socket5 to HTTP 这是一个超简单的 Socket5 代理转换成 HTTP 代理的小工具。 如何安装? Golang 用户 # Required Go 1.17+ go install github.com/mritd/s2h@master Docker 用户 docker pull m

Jan 2, 2023

IP2Proxy Go package allows users to query an IP address to determine if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits.

IP2Proxy Go Package This package allows user to query an IP address if it was being used as VPN anonymizer, open proxies, web proxies, Tor exits, data

Sep 15, 2022

Tcp-proxy - A dead simple reverse proxy server.

tcp-proxy A proxy that forwords from a host to another. Building go build -ldflags="-X 'main.Version=$(git describe --tags $(git rev-list --tags --max

Jan 2, 2022

Proxy - Minimalistic TCP relay proxy.

Proxy Minimalistic TCP relay proxy. Installation ensure you have go = 1.17 installed clone the repo cd proxy go install main.go Examples Listen on po

May 22, 2022

Http-logging-proxy - A HTTP Logging Proxy For Golang

http-logging-proxy HTTP Logging Proxy Description This project builds a simple r

Aug 1, 2022

Battlesnake-logging-proxy - A little proxy between the internet and your battlesnake

battlesnake-logging-proxy a little proxy between the internet and your battlesna

Feb 11, 2022

Given a list of domains, you resolve them and get the IP addresses.

Given a list of domains, you resolve them and get the IP addresses.

resolveDomains Given a list of domains, you resolve them and get the IP addresses. Installation If you want to make modifications locally and compile

Oct 19, 2022
[WIP] gg is a portable tool to redirect the traffic of a given program to your modern proxy without installing any other programs.

gg gg (go-graft), was inspired by graftcp. go-graft is a pure golang implementation with more useful features. TODO: Use system DNS as the fallback. R

Dec 28, 2022
Traefik plugin to proxy requests to owasp/modsecurity-crs:apache container
Traefik plugin to proxy requests to owasp/modsecurity-crs:apache container

Traefik Modsecurity Plugin Traefik plugin to proxy requests to owasp/modsecurity-crs:apache Traefik Modsecurity Plugin Demo Full Configuration with do

Dec 27, 2022
Mar 21, 2022
This is a tool that will proxy simple HTTPS requests to an external HTTP endpoint
 This is a tool that will proxy simple HTTPS requests to an external HTTP endpoint

AcmeShield A secured HTTP proxy that forwards requests from a remote service(Postman). This is a tool that will proxy simple HTTPS requests to an exte

Mar 21, 2022
llb - It's a very simple but quick backend for proxy servers. Can be useful for fast redirection to predefined domain with zero memory allocation and fast response.

llb What the f--k it is? It's a very simple but quick backend for proxy servers. You can setup redirect to your main domain or just show HTTP/1.1 404

Sep 27, 2022
Proxy that keeps clients active until the backend server is back online

HoneySmoke HoneySmoke is a prototype proxy for testing until it eventually becomes HoneyHive. HoneySmoke will eventually implement a limbo mode that k

Nov 20, 2021
A http-relay server/client written in golang to forward requests to a service behind a nat router from web

http-relay This repo is WIP http-relay is a server/client application written in go(lang) to forward http(s) requests to an application behind a nat r

Dec 16, 2021
🍔 Product-storage service, work on gRPC. Client sends the URL to download products, and requests the result.

?? Product-storage service, work on gRPC. Client sends the URL to download products, and requests the result. The server transfer request to a third-party resource for .csv-file uploading and saves the products to own database.

Dec 16, 2021