From 4f3584247361544ad238de101458d5b179198b32 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 26 Sep 2020 09:30:50 +0200 Subject: [PATCH] Only attempt to read thumbnails when we get a 200 response code. We would have been able to keep doing this if the Network Request code followed redirects - however, it doesn't, so this is the best we can do. We also don't have header support in Network Result, so we can't validate that the response we got is actually an image. Fixes #1972 --- src/widgets/splits/SplitHeader.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index 2bfa40a4f..6176bd817 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -594,6 +594,7 @@ void SplitHeader::updateChannelText() if (streamStatus->live) { this->isLive_ = true; + // XXX: This URL format can be figured out from the Helix Get Streams API which we parse in TwitchChannel::parseLiveStatus QString url = "https://static-cdn.jtvnw.net/" "previews-ttv/live_user_" + channel->getName().toLower(); @@ -617,9 +618,17 @@ void SplitHeader::updateChannelText() { NetworkRequest(url, NetworkRequestType::Get) .onSuccess([this](auto result) -> Outcome { - this->thumbnail_ = - QString::fromLatin1(result.getData().toBase64()); - updateChannelText(); + // NOTE: We do not follow the redirects, so we need to make sure we only treat code 200 as a valid image + if (result.status() == 200) + { + this->thumbnail_ = QString::fromLatin1( + result.getData().toBase64()); + } + else + { + this->thumbnail_.clear(); + } + this->updateChannelText(); return Success; }) .execute();