Skip to content

Commit 51b5485

Browse files
committed
Add preliminary support for nitter-proxy
1 parent 663f5a5 commit 51b5485

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

nitter.example.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enableRSS = true # set this to false to disable RSS feeds
2626
enableDebug = false # enable request logs and debug endpoints (/.sessions)
2727
proxy = "" # http/https url, SOCKS proxies are not supported
2828
proxyAuth = ""
29+
apiProxy = "" # nitter-proxy host, e.g. localhost:7000
2930
disableTid = false # enable this if cookie-based auth is failing
3031

3132
# Change default preferences here, see src/prefs_impl.nim for a complete list

src/apiutils.nim

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@ const
1313
var
1414
pool: HttpPool
1515
disableTid: bool
16+
apiProxy: string
1617

1718
proc setDisableTid*(disable: bool) =
1819
disableTid = disable
1920

21+
proc setApiProxy*(url: string) =
22+
if url.len > 0:
23+
apiProxy = url.strip(chars={'/'}) & "/"
24+
if "http" notin apiProxy:
25+
apiProxy = "http://" & apiProxy
26+
2027
proc toUrl(req: ApiReq; sessionKind: SessionKind): Uri =
2128
case sessionKind
2229
of oauth:
@@ -99,7 +106,11 @@ template fetchImpl(result, fetchBody) {.dirty.} =
99106
var resp: AsyncResponse
100107
pool.use(await genHeaders(session, url)):
101108
template getContent =
102-
resp = await c.get($url)
109+
# TODO: this is a temporary simple implementation
110+
if apiProxy.len > 0:
111+
resp = await c.get(($url).replace("https://", apiProxy))
112+
else:
113+
resp = await c.get($url)
103114
result = await resp.body
104115

105116
getContent()

src/config.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ proc getConfig*(path: string): (Config, parseCfg.Config) =
4141
enableDebug: cfg.get("Config", "enableDebug", false),
4242
proxy: cfg.get("Config", "proxy", ""),
4343
proxyAuth: cfg.get("Config", "proxyAuth", ""),
44+
apiProxy: cfg.get("Config", "apiProxy", ""),
4445
disableTid: cfg.get("Config", "disableTid", false)
4546
)
4647

src/nitter.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ setHmacKey(cfg.hmacKey)
3737
setProxyEncoding(cfg.base64Media)
3838
setMaxHttpConns(cfg.httpMaxConns)
3939
setHttpProxy(cfg.proxy, cfg.proxyAuth)
40+
setApiProxy(cfg.apiProxy)
4041
setDisableTid(cfg.disableTid)
4142
initAboutPage(cfg.staticDir)
4243

src/types.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ type
275275
enableDebug*: bool
276276
proxy*: string
277277
proxyAuth*: string
278+
apiProxy*: string
278279
disableTid*: bool
279280

280281
rssCacheTime*: int

0 commit comments

Comments
 (0)