Add "Bot" to User Agent to coerce Twitter into serving OGP <meta> tags.
authorMark Felder <feld@FreeBSD.org>
Tue, 7 Jul 2020 16:21:05 +0000 (11:21 -0500)
committerMark Felder <feld@FreeBSD.org>
Tue, 7 Jul 2020 16:21:05 +0000 (11:21 -0500)
CHANGELOG.md
lib/pleroma/web/rich_media/parser.ex

index 0e2b549163407cbf8d3aeff420a3085861a3f5ec..be0bf4f02d09ba65e694aab2e0b629dcf86ca2cf 100644 (file)
@@ -76,6 +76,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - Resolving Peertube accounts with Webfinger
 - `blob:` urls not being allowed by connect-src CSP
 - Mastodon API: fix `GET /api/v1/notifications` not returning the full result set
+- Rich Media Previews for Twitter links
 
 ## [Unreleased (patch)]
 
index ef5ead2daf1fdcad1309591344223c07513f5136..c8a767935333c50fae6037789866bcee49e1299f 100644 (file)
@@ -86,7 +86,10 @@ defmodule Pleroma.Web.RichMedia.Parser do
       end
 
     try do
-      {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: opts)
+      rich_media_agent = Pleroma.Application.user_agent() <> "; Bot"
+
+      {:ok, %Tesla.Env{body: html}} =
+        Pleroma.HTTP.get(url, [{"user-agent", rich_media_agent}], adapter: opts)
 
       html
       |> parse_html()