mirror of
https://github.com/zedeus/nitter
synced 2026-09-05 14:49:32 +00:00
parent
2ccebaf22a
commit
0bc9702854
1 changed files with 18 additions and 0 deletions
|
|
@ -11,6 +11,20 @@ const
|
||||||
npCache = "x-np-cache"
|
npCache = "x-np-cache"
|
||||||
errorsToSkip = {null, doesntExist, tweetNotFound, timeout, unauthorized, badRequest}
|
errorsToSkip = {null, doesntExist, tweetNotFound, timeout, unauthorized, badRequest}
|
||||||
|
|
||||||
|
proc isCloudflareHtml*(body: string): bool =
|
||||||
|
## Detect Cloudflare HTML error pages returned instead of JSON
|
||||||
|
if body.len < 14 or body[0] != '<': return false
|
||||||
|
body[0 ..< 14].toLowerAscii() == "<!doctype html" and "Cloudflare" in body
|
||||||
|
|
||||||
|
proc cfTitle*(body: string): string =
|
||||||
|
## Extract <title> from Cloudflare HTML for log diagnostics
|
||||||
|
let start = body.find("<title>")
|
||||||
|
if start < 0: return "unknown"
|
||||||
|
let contentStart = start + 7
|
||||||
|
let stop = body.find("</title>", contentStart)
|
||||||
|
if stop < 0: return "unknown"
|
||||||
|
body[contentStart ..< stop].splitWhitespace().join(" ")
|
||||||
|
|
||||||
var
|
var
|
||||||
pool: HttpPool
|
pool: HttpPool
|
||||||
disableTid: bool
|
disableTid: bool
|
||||||
|
|
@ -151,6 +165,10 @@ template fetchImpl(result, fetchBody) {.dirty.} =
|
||||||
if resp.headers.getOrDefault("content-encoding") == "gzip":
|
if resp.headers.getOrDefault("content-encoding") == "gzip":
|
||||||
result = uncompress(result, dfGzip)
|
result = uncompress(result, dfGzip)
|
||||||
|
|
||||||
|
if isCloudflareHtml(result):
|
||||||
|
echo "[cloudflare] ", resp.status, " (", cfTitle(result), "), API: ", url.path, ", session: ", session.pretty
|
||||||
|
raise rateLimitError()
|
||||||
|
|
||||||
if result.startsWith("{\"errors"):
|
if result.startsWith("{\"errors"):
|
||||||
let errors = result.fromJson(Errors)
|
let errors = result.fromJson(Errors)
|
||||||
if errors notin errorsToSkip:
|
if errors notin errorsToSkip:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue