Skip to content

Commit 88f8773

Browse files
committed
feat: add proxy support to tid HTTP client
- Add getHttpProxy() function to expose proxy configuration from http_pool - Update tid.nim to use proxy when creating AsyncHttpClient - Add debug logging statements in apiutils.nim and redis_cache.nim for troubleshooting
1 parent 7ca4f79 commit 88f8773

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

src/apiutils.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ proc fetchRaw*(req: ApiReq): Future[string] {.async.} =
197197
var session = await getAndValidateSession(req)
198198
let url = req.toUrl(session.kind)
199199

200+
echo "fetchRaw url: ", url
201+
200202
fetchImpl result:
203+
echo "fetchRaw result: ", result
201204
if not (result.startsWith('{') or result.startsWith('[')):
202205
echo resp.status, ": ", result, " --- url: ", url
203206
result.setLen(0)

src/http_pool.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ proc setHttpProxy*(url: string; auth: string) =
1818
else:
1919
proxy = nil
2020

21+
proc getHttpProxy*(): Proxy =
22+
return proxy
23+
2124
proc release*(pool: HttpPool; client: AsyncHttpClient; badClient=false) =
2225
if pool.conns.len >= maxConns or badClient:
2326
try: client.close()

src/redis_cache.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ proc getCachedUsername*(userId: string): Future[string] {.async.} =
142142
if username != redisNil:
143143
result = username
144144
else:
145+
echo "getGraphUserById: ", userId
145146
let user = await getGraphUserById(userId)
147+
echo "user: ", user
148+
146149
result = user.username
147150
await setEx(key, baseCacheTime, result)
148151
if result.len > 0 and user.id.len > 0:

src/tid.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import std/[asyncdispatch, base64, httpclient, random, strutils, sequtils, times]
22
import nimcrypto
33
import experimental/parser/tid
4+
import http_pool
45

56
randomize()
67

@@ -18,7 +19,7 @@ proc getPair(): Future[TidPair] {.async.} =
1819
if cachedPairs.len == 0 or int(epochTime()) - lastCached > ttlSec:
1920
lastCached = int(epochTime())
2021

21-
let client = newAsyncHttpClient()
22+
let client = newAsyncHttpClient(proxy=getHttpProxy())
2223
defer: client.close()
2324

2425
let resp = await client.get(pairsUrl)

0 commit comments

Comments
 (0)