-
Notifications
You must be signed in to change notification settings - Fork 16
/
http-proxy.node.txt
63 lines (58 loc) · 5.12 KB
/
http-proxy.node.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
HTTP-PROXY
HTTP-PROXY. #Returns PROXY. Version 1.1.6
createProxyServer #Can be used for both forward and reverse proxies (according to how PARAM_OBJ.target is set)
(PARAM_OBJ) #Can proxy http[s]:// and ws:// connections
PROXY.web #Proxies current request to PARAM_OBJ.target URL.
(REQ,RES[,PARAM_OBJ]) #Should be used as request event handler or Express MIDWR.
# - HTTP[S].request() URL -> CLIENTREQUEST:
# - uses REQ method, headers and body
# - do several other ACTION:
# - "deleteLength": sets Content-Length: 0 [C] if missing and METHOD is DELETE
# - "timeout": SOCKET.setTimeout(PARAM_OBJ.timeout)
# - "XHeaders": if PARAM_OBJ.xfwd true (def: false), sets (or appends)
# X-Forwarded-For|Port|Proto [C] according to REQ
# - "stream": the actual request()
# - can add other ACTION with:
# PROXY.before|after("web|ws", ACTION_STR, FUNC(REQ,RES,PARAM_OBJ,HEAD_ARR,PROXY,FUNC2(...)))
# - FUNC2(...) is error callback, same as error event handler
# - can modify HTTP[S].request(PARAM_OBJ2):
# - headers: augmented by PARAM_OBJ.headers, and Connection: close [C]
# (unless specified otherwise)
# - rejectUnauthorized BOOL: PARAM_OBJ.secure
# - PARAM_OBJ.ssl (same as TLS.createServer() OBJ)
# - agent: PARAM_OBJ.agent
# - localAddress: PARAM_OBJ.localAddress
# - if PARAM_OBJ.toProxy true, uses REQ.url (and not path) as path. To do if there is another
# proxy.
# - Transfer URL response REQ2 to RES:
# - uses REQ status code, headers and body
# - sets Connection: keep-alive [C]
# - abort after PARAM_OBJ.proxyTimeout (in sec)
#Events:
# - proxyReq FUNC(CLIENTREQUEST, REQ, RES, PARAM_OBJ): to modify CLIENTREQUEST before sent
# - proxyRes FUNC(REQ2, REQ, RES): to modify REQ2 before sent back to RES
# - start FUNC(URL): at beginning of "stream" action
# - end FUNC(REQ, RES, REQ2)
# - error FUNC(ERROR, REQ, RES, URL)
#PARAM_OBJ.forward URL:
# - same as PARAM_OBJ.target URL, but don't get/transfer the answer.
# - Can be used on top of PARAM_OBJ.target, to forward the request.
PROXY.ws(REQ, SOCKET #Proxies also Upgrade: websocket [C] requests and Websocket traffic.
, BUFFER[, OBJ]) #Should be used in upgrade event handler.
#Details:
# - transfer HTTP[S].request() to OBJ.target URL
# - if target replies with Upgrade: websocket [S], replies to original sender with 101 status code
# and reply headers
# - then pipe input|output original sender SOCKET with OBJ.target SOCKET2 (Websocket traffic)
#Details:
# - not not use ACTION "deleteLength" and "timeout", cannot use OBJ.forward
# - uses protocol ws:// or wss://
# - sets SOCKET: setTimeout(0), setNoDelay(true), setKeepAlive(true, 0)
# - error event handler: FUNC(ERROR, REQ, SOCKET)
PROXY.listen(...) #Shortcut. Assigns PROXY._server = HTTP[S].SERVER, that:
# - uses PROXY.web as request event handler
# - if PARAM_OBJ.ws true, PROXY.ws as upgrade event handler
# - listen(...)
#Returns PROXY