Skip to content

Commit 500c1d5

Browse files
committed
js: docs WIP
1 parent 6729fb3 commit 500c1d5

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Dumbest HTTP proxy ever.
2424
* Resilient to DPI (including active probing, see `hidden_domain` option for authentication providers)
2525
* Connecting via upstream HTTP(S)/SOCKS5 proxies (proxy chaining)
2626
* systemd socket activation
27+
* Scripting with JavaScript:
28+
* Access filter by JS function
29+
* Upstream proxy selection by JS function
2730

2831
## Installation
2932

@@ -175,6 +178,35 @@ Authentication parameters are passed as URI via `-auth` parameter. Scheme of URI
175178
* `blacklist` - location of file with list of serial numbers of blocked certificates, one per each line in form of hex-encoded colon-separated bytes. Example: `ab:01:02:03`. Empty lines and comments starting with `#` are ignored.
176179
* `reload` - interval for certificate blacklist file reload, if it was modified since last load. Use negative duration to disable autoreload. Default: `15s`.
177180

181+
## Scripting
182+
183+
With the dumbproxy, it is possible to modify request processing behaviour using simple scripts written in the JavaScript programming language.
184+
185+
### Access by JS script
186+
187+
It is possible to filter (allow or deny) requests with simple `access` JS function. Such function can be loaded with the `-js-access-filter` option. Option value must specify location of script file where `access` function is defined.
188+
189+
`access` function is invoked with following parameters:
190+
191+
1. Request *(Object)*. It contains following properties:
192+
* **method** *(string)* - HTTP method used in request (CONNECT, GET, POST, PUT, etc.).
193+
* **url** *(string)* - URL parsed from the URI supplied on the Request-Line.
194+
* **proto** *(string)* - the protocol version for incoming server requests.
195+
* **protoMajor** *(Number)* - numeric major protocol version.
196+
* **protoMinor** *(Number)* - numeric minor protocol version.
197+
* **header** *(Object)* - mapping of *String* headers (except Host) in canonical form to *Array* of their *String* values.
198+
* **contentLength** *(Number)* - length of request body, if known.
199+
* **transferEncoding** *(Array)* - lists the request's transfer encodings from outermost to innermost.
200+
* **host** *(String)* - specifies the host on which the URL is sought. For HTTP/1 (per RFC 7230, section 5.4), this is either the value of the "Host" header or the host name given in the URL itself. For HTTP/2, it is the value of the ":authority" pseudo-header field.
201+
* **remoteAddr** *(String)* - client's IP:port.
202+
* **requestURI** *(String)* - the unmodified request-target of the Request-Line (RFC 7230, Section 3.1.1) as sent by the client to a server.
203+
2. Destination address *(Object)*. It's an address where actual connection is about to be created. It contains following properties:
204+
* **network** *(String)* - connection type. Should be `"tcp"` in most cases unless restricted to specific address family (`"tcp4"` or `"tcp6"`).
205+
* **originalHost** *(String)* - original hostname or IP address parsed from request.
206+
* **resolvedHost** *(String)* - resolved hostname from request.
207+
* **port** *(Number)* - port number.
208+
* Username *(String)*. Name of the authenticated user or an empty string if there is no authentication.
209+
178210
## Synopsis
179211

180212
```
@@ -224,6 +256,14 @@ Usage of /home/user/go/bin/dumbproxy:
224256
sign username with specified key for given validity period. Positional arguments are: hex-encoded HMAC key, username, validity duration.
225257
-ip-hints string
226258
a comma-separated list of source addresses to use on dial attempts. "$lAddr" gets expanded to local address of connection. Example: "10.0.0.1,fe80::2,$lAddr,0.0.0.0,::"
259+
-js-access-filter string
260+
path to JS script file with the "access" filter function
261+
-js-access-filter-instances int
262+
number of JS VM instances to handle access filter requests (default 4)
263+
-js-proxy-router value
264+
path to JS script file with the "getProxy" function
265+
-js-proxy-router-instances int
266+
number of JS VM instances to handle proxy router requests (default 4)
227267
-key string
228268
key for TLS certificate
229269
-list-ciphers

jsext/dto.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ type JSRequestInfo struct {
2121
ContentLength int64 `json:"contentLength"`
2222
TransferEncoding []string `json:"transferEncoding"`
2323
Host string `json:"host"`
24-
Form url.Values `json:"form"`
25-
PostForm url.Values `json:"portForm"`
26-
MultipartForm *multipart.Form `json:"multipartForm"`
27-
Trailer http.Header `json:"trailer"`
2824
RemoteAddr string `json:"remoteAddr"`
2925
RequestURI string `json:"requestURI"`
3026
}
@@ -40,10 +36,6 @@ func JSRequestInfoFromRequest(req *http.Request) *JSRequestInfo {
4036
ContentLength: req.ContentLength,
4137
TransferEncoding: req.TransferEncoding,
4238
Host: req.Host,
43-
Form: req.Form,
44-
PostForm: req.PostForm,
45-
MultipartForm: req.MultipartForm,
46-
Trailer: req.Trailer,
4739
RemoteAddr: req.RemoteAddr,
4840
RequestURI: req.RequestURI,
4941
}

0 commit comments

Comments
 (0)