Temporary fix to Twitter's global timeline error

This commit is contained in:
Zed 2022-01-21 09:17:18 +01:00
commit cdb4efadfe
3 changed files with 31 additions and 16 deletions

View file

@ -1,5 +1,5 @@
# SPDX-License-Identifier: AGPL-3.0-only
import asyncdispatch, httpclient
import httpclient
type
HttpPool* = ref object
@ -17,20 +17,22 @@ proc setHttpProxy*(url: string; auth: string) =
else:
proxy = nil
proc release*(pool: HttpPool; client: AsyncHttpClient) =
if pool.conns.len >= maxConns:
client.close()
proc release*(pool: HttpPool; client: AsyncHttpClient; badClient=false) =
if pool.conns.len >= maxConns or badClient:
try: client.close()
except: discard
elif client != nil:
pool.conns.insert(client)
template use*(pool: HttpPool; heads: HttpHeaders; body: untyped): untyped =
var c {.inject.}: AsyncHttpClient
proc acquire*(pool: HttpPool; heads: HttpHeaders): AsyncHttpClient =
if pool.conns.len == 0:
c = newAsyncHttpClient(headers=heads, proxy=proxy)
result = newAsyncHttpClient(headers=heads, proxy=proxy)
else:
c = pool.conns.pop()
c.headers = heads
result = pool.conns.pop()
result.headers = heads
template use*(pool: HttpPool; heads: HttpHeaders; body: untyped): untyped =
let c {.inject.} = pool.acquire(heads)
try:
body