Skip to content

Commit ebffb6d

Browse files
authored
Merge pull request #443 from jackyzy823/proxy
Add proxy for outgoing request
2 parents c09a8d8 + 6aa913a commit ebffb6d

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

nitter.example.conf

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ redisMaxConnections = 30
2323
hmacKey = "secretkey" # random key for cryptographic signing of video urls
2424
base64Media = false # use base64 encoding for proxied media urls
2525
enableRSS = true # set this to false to disable RSS feeds
26+
proxy = "" # proxy type http/https
27+
proxyAuth = ""
2628
tokenCount = 10
2729
# minimum amount of usable tokens. tokens are used to authorize API requests,
2830
# but they expire after ~1 hour, and have a limit of 187 requests.

src/config.nim

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ proc getConfig*(path: string): (Config, parseCfg.Config) =
2727
base64Media: cfg.get("Config", "base64Media", false),
2828
minTokens: cfg.get("Config", "tokenCount", 10),
2929
enableRss: cfg.get("Config", "enableRSS", true),
30+
proxy: cfg.get("Config", "proxy", ""),
31+
proxyAuth: cfg.get("Config", "proxyAuth", ""),
3032

3133
listCacheTime: cfg.get("Cache", "listMinutes", 120),
3234
rssCacheTime: cfg.get("Cache", "rssMinutes", 10),

src/http_pool.nim

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ type
66
conns*: seq[AsyncHttpClient]
77

88
var maxConns {.threadvar.}: int
9+
var proxy {.threadvar.}: Proxy
910

1011
proc setMaxHttpConns*(n: int) =
1112
maxConns = n
1213

14+
proc setHttpProxy*(url: string; auth: string) =
15+
if url.len > 0:
16+
proxy = newProxy(url, auth)
17+
else:
18+
proxy = nil
19+
1320
proc release*(pool: HttpPool; client: AsyncHttpClient) =
1421
if pool.conns.len >= maxConns:
1522
client.close()
@@ -20,7 +27,7 @@ template use*(pool: HttpPool; heads: HttpHeaders; body: untyped): untyped =
2027
var c {.inject.}: AsyncHttpClient
2128

2229
if pool.conns.len == 0:
23-
c = newAsyncHttpClient(headers=heads)
30+
c = newAsyncHttpClient(headers=heads, proxy=proxy)
2431
else:
2532
c = pool.conns.pop()
2633
c.headers = heads

src/nitter.nim

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ setCacheTimes(cfg)
3232
setHmacKey(cfg.hmacKey)
3333
setProxyEncoding(cfg.base64Media)
3434
setMaxHttpConns(cfg.httpMaxConns)
35+
setHttpProxy(cfg.proxy, cfg.proxyAuth)
3536

3637
waitFor initRedisPool(cfg)
3738
stdout.write &"Connected to Redis at {cfg.redisHost}:{cfg.redisPort}\n"

src/types.nim

+2
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ type
217217
base64Media*: bool
218218
minTokens*: int
219219
enableRss*: bool
220+
proxy*: string
221+
proxyAuth*: string
220222

221223
rssCacheTime*: int
222224
listCacheTime*: int

0 commit comments

Comments
 (0)