diff --git a/src/apiutils.nim b/src/apiutils.nim index 2ea4424..fc433ae 100644 --- a/src/apiutils.nim +++ b/src/apiutils.nim @@ -49,11 +49,15 @@ proc fetch*(url: Uri; oldApi=false): Future[JsonNode] {.async.} = let headers = genHeaders(token) try: var resp: AsyncResponse - let body = pool.use(headers): + var body = pool.use(headers): resp = await c.get($url) - let raw = await resp.body - if raw.len == 0: "" - else: uncompress(raw) + await resp.body + + if body.len > 0: + if resp.headers.getOrDefault("content-encoding") == "gzip": + body = uncompress(body, dfGzip) + else: + echo "non-gzip body, url: ", url, ", body: ", body if body.startsWith('{') or body.startsWith('['): result = parseJson(body) diff --git a/src/routes/timeline.nim b/src/routes/timeline.nim index 65d2652..6922012 100644 --- a/src/routes/timeline.nim +++ b/src/routes/timeline.nim @@ -78,9 +78,6 @@ proc fetchSingleTimeline*(after: string; query: Query; skipRail=false): return (profile, timeline, await rail) -proc get*(req: Request; key: string): string = - params(req).getOrDefault(key) - proc showTimeline*(request: Request; query: Query; cfg: Config; prefs: Prefs; rss, after: string): Future[string] {.async.} = if query.fromUser.len != 1: