Skip to content

Commit

Permalink
Add http proxy config
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzy823 committed Dec 28, 2021
1 parent 1e1e034 commit 6aa913a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions nitter.example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ redisMaxConnections = 30
hmacKey = "secretkey" # random key for cryptographic signing of video urls
base64Media = false # use base64 encoding for proxied media urls
enableRSS = true # set this to false to disable RSS feeds
proxy = "" # proxy type http/https
proxyAuth = ""
tokenCount = 10
# minimum amount of usable tokens. tokens are used to authorize API requests,
# but they expire after ~1 hour, and have a limit of 187 requests.
Expand Down
2 changes: 2 additions & 0 deletions src/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ proc getConfig*(path: string): (Config, parseCfg.Config) =
base64Media: cfg.get("Config", "base64Media", false),
minTokens: cfg.get("Config", "tokenCount", 10),
enableRss: cfg.get("Config", "enableRSS", true),
proxy: cfg.get("Config", "proxy", ""),
proxyAuth: cfg.get("Config", "proxyAuth", ""),

listCacheTime: cfg.get("Cache", "listMinutes", 120),
rssCacheTime: cfg.get("Cache", "rssMinutes", 10),
Expand Down
9 changes: 8 additions & 1 deletion src/http_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ type
conns*: seq[AsyncHttpClient]

var maxConns {.threadvar.}: int
var proxy {.threadvar.}: Proxy

proc setMaxHttpConns*(n: int) =
maxConns = n

proc setHttpProxy*(url: string; auth: string) =
if url.len > 0:
proxy = newProxy(url, auth)
else:
proxy = nil

proc release*(pool: HttpPool; client: AsyncHttpClient) =
if pool.conns.len >= maxConns:
client.close()
Expand All @@ -20,7 +27,7 @@ template use*(pool: HttpPool; heads: HttpHeaders; body: untyped): untyped =
var c {.inject.}: AsyncHttpClient

if pool.conns.len == 0:
c = newAsyncHttpClient(headers=heads)
c = newAsyncHttpClient(headers=heads, proxy=proxy)
else:
c = pool.conns.pop()
c.headers = heads
Expand Down
1 change: 1 addition & 0 deletions src/nitter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ setCacheTimes(cfg)
setHmacKey(cfg.hmacKey)
setProxyEncoding(cfg.base64Media)
setMaxHttpConns(cfg.httpMaxConns)
setHttpProxy(cfg.proxy, cfg.proxyAuth)

waitFor initRedisPool(cfg)
stdout.write &"Connected to Redis at {cfg.redisHost}:{cfg.redisPort}\n"
Expand Down
2 changes: 2 additions & 0 deletions src/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ type
base64Media*: bool
minTokens*: int
enableRss*: bool
proxy*: string
proxyAuth*: string

rssCacheTime*: int
listCacheTime*: int
Expand Down

0 comments on commit 6aa913a

Please sign in to comment.