mirror of
https://github.com/zedeus/nitter
synced 2026-09-06 15:19:32 +00:00
Add user agent for media requests, improve error
This commit is contained in:
parent
9b34123573
commit
7acea6b9e0
2 changed files with 18 additions and 13 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import strutils, sequtils, asyncdispatch, httpclient, uri
|
||||
from jester import Request
|
||||
import ../utils, ../prefs
|
||||
import ".."/[utils, prefs]
|
||||
export utils, prefs
|
||||
|
||||
template savePref*(pref, value: string; req: Request; expire=false) =
|
||||
|
|
@ -33,8 +33,8 @@ proc safeClose*(client: AsyncHttpClient) =
|
|||
try: client.close()
|
||||
except: discard
|
||||
|
||||
proc safeFetch*(url: string): Future[string] {.async.} =
|
||||
let client = newAsyncHttpClient()
|
||||
proc safeFetch*(url, agent: string): Future[string] {.async.} =
|
||||
let client = newAsyncHttpClient(userAgent=agent)
|
||||
try: result = await client.getContent(url)
|
||||
except: discard
|
||||
finally: client.safeClose()
|
||||
|
|
|
|||
Loading…
Reference in a new issue