diff --git a/src/settings/subsonicsettingspage.cpp b/src/settings/subsonicsettingspage.cpp index b5ab2154f..aa70bbe28 100644 --- a/src/settings/subsonicsettingspage.cpp +++ b/src/settings/subsonicsettingspage.cpp @@ -58,6 +58,10 @@ SubsonicSettingsPage::SubsonicSettingsPage(SettingsDialog *parent) dialog()->installEventFilter(this); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) + ui_->checkbox_http2->hide(); +#endif + } SubsonicSettingsPage::~SubsonicSettingsPage() { delete ui_; } @@ -72,6 +76,7 @@ void SubsonicSettingsPage::Load() { QByteArray password = s.value("password").toByteArray(); if (password.isEmpty()) ui_->password->clear(); else ui_->password->setText(QString::fromUtf8(QByteArray::fromBase64(password))); + ui_->checkbox_http2->setChecked(s.value("http2", true).toBool()); ui_->checkbox_verify_certificate->setChecked(s.value("verifycertificate", false).toBool()); ui_->checkbox_download_album_covers->setChecked(s.value("downloadalbumcovers", true).toBool()); ui_->checkbox_server_scrobbling->setChecked(s.value("serversidescrobbling", false).toBool()); @@ -91,6 +96,7 @@ void SubsonicSettingsPage::Save() { s.setValue("url", QUrl(ui_->server_url->text())); s.setValue("username", ui_->username->text()); s.setValue("password", QString::fromUtf8(ui_->password->text().toUtf8().toBase64())); + s.setValue("http2", ui_->checkbox_http2->isChecked()); s.setValue("verifycertificate", ui_->checkbox_verify_certificate->isChecked()); s.setValue("downloadalbumcovers", ui_->checkbox_download_album_covers->isChecked()); s.setValue("serversidescrobbling", ui_->checkbox_server_scrobbling->isChecked()); diff --git a/src/settings/subsonicsettingspage.ui b/src/settings/subsonicsettingspage.ui index 7aa7a6d82..98bf75505 100644 --- a/src/settings/subsonicsettingspage.ui +++ b/src/settings/subsonicsettingspage.ui @@ -106,6 +106,13 @@ Preferences + + + + Use HTTP2 when possible + + + diff --git a/src/subsonic/subsonicbaserequest.cpp b/src/subsonic/subsonicbaserequest.cpp index 8b2b4bc04..c7d35fe95 100644 --- a/src/subsonic/subsonicbaserequest.cpp +++ b/src/subsonic/subsonicbaserequest.cpp @@ -100,6 +100,10 @@ QNetworkReply *SubsonicBaseRequest::CreateGetRequest(const QString &ressource_na req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); #endif +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + req.setAttribute(QNetworkRequest::Http2AllowedAttribute, http2()); +#endif + QNetworkReply *reply = network_->get(req); QObject::connect(reply, &QNetworkReply::sslErrors, this, &SubsonicBaseRequest::HandleSSLErrors); diff --git a/src/subsonic/subsonicbaserequest.h b/src/subsonic/subsonicbaserequest.h index 005db0a1f..b81fc90d6 100644 --- a/src/subsonic/subsonicbaserequest.h +++ b/src/subsonic/subsonicbaserequest.h @@ -61,13 +61,14 @@ class SubsonicBaseRequest : public QObject { virtual void Error(const QString &error, const QVariant &debug = QVariant()) = 0; QString ErrorsToHTML(const QStringList &errors); - QString client_name() { return service_->client_name(); } - QString api_version() { return service_->api_version(); } - QUrl server_url() { return service_->server_url(); } - QString username() { return service_->username(); } - QString password() { return service_->password(); } - bool verify_certificate() { return service_->verify_certificate(); } - bool download_album_covers() { return service_->download_album_covers(); } + QString client_name() const { return service_->client_name(); } + QString api_version() const { return service_->api_version(); } + QUrl server_url() const { return service_->server_url(); } + QString username() const { return service_->username(); } + QString password() const { return service_->password(); } + bool http2() const { return service_->http2(); } + bool verify_certificate() const { return service_->verify_certificate(); } + bool download_album_covers() const { return service_->download_album_covers(); } private slots: void HandleSSLErrors(QList ssl_errors); diff --git a/src/subsonic/subsonicrequest.cpp b/src/subsonic/subsonicrequest.cpp index d7d074394..a4aafa95b 100644 --- a/src/subsonic/subsonicrequest.cpp +++ b/src/subsonic/subsonicrequest.cpp @@ -735,6 +735,10 @@ void SubsonicRequest::FlushAlbumCoverRequests() { req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); #endif +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + req.setAttribute(QNetworkRequest::Http2AllowedAttribute, http2()); +#endif + if (!verify_certificate()) { QSslConfiguration sslconfig = QSslConfiguration::defaultConfiguration(); sslconfig.setPeerVerifyMode(QSslSocket::VerifyNone); diff --git a/src/subsonic/subsonicservice.cpp b/src/subsonic/subsonicservice.cpp index 53036dff6..739b672fb 100644 --- a/src/subsonic/subsonicservice.cpp +++ b/src/subsonic/subsonicservice.cpp @@ -73,6 +73,7 @@ SubsonicService::SubsonicService(Application *app, QObject *parent) collection_backend_(nullptr), collection_model_(nullptr), collection_sort_model_(new QSortFilterProxyModel(this)), + http2_(true), verify_certificate_(false), download_album_covers_(true), ping_redirects_(0) @@ -138,6 +139,7 @@ void SubsonicService::ReloadSettings() { if (password.isEmpty()) password_.clear(); else password_ = QString::fromUtf8(QByteArray::fromBase64(password)); + http2_ = s.value("http2", true).toBool(); verify_certificate_ = s.value("verifycertificate", false).toBool(); download_album_covers_ = s.value("downloadalbumcovers", true).toBool(); @@ -196,6 +198,10 @@ void SubsonicService::SendPingWithCredentials(QUrl url, const QString &username, req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + req.setAttribute(QNetworkRequest::Http2AllowedAttribute, http2_); +#endif + errors_.clear(); QNetworkReply *reply = network_->get(req); replies_ << reply; diff --git a/src/subsonic/subsonicservice.h b/src/subsonic/subsonicservice.h index 873f050b5..aacbbaff0 100644 --- a/src/subsonic/subsonicservice.h +++ b/src/subsonic/subsonicservice.h @@ -62,19 +62,20 @@ class SubsonicService : public InternetService { void ReloadSettings() override; void Exit() override; - Application *app() { return app_; } + Application *app() const { return app_; } - QString client_name() { return kClientName; } - QString api_version() { return kApiVersion; } - QUrl server_url() { return server_url_; } - QString username() { return username_; } - QString password() { return password_; } - bool verify_certificate() { return verify_certificate_; } - bool download_album_covers() { return download_album_covers_; } + QString client_name() const { return kClientName; } + QString api_version() const { return kApiVersion; } + QUrl server_url() const { return server_url_; } + QString username() const { return username_; } + QString password() const { return password_; } + bool http2() const { return http2_; } + bool verify_certificate() const { return verify_certificate_; } + bool download_album_covers() const { return download_album_covers_; } - CollectionBackend *collection_backend() { return collection_backend_; } - CollectionModel *collection_model() { return collection_model_; } - QSortFilterProxyModel *collection_sort_model() { return collection_sort_model_; } + CollectionBackend *collection_backend() const { return collection_backend_; } + CollectionModel *collection_model() const { return collection_model_; } + QSortFilterProxyModel *collection_sort_model() const { return collection_sort_model_; } CollectionBackend *songs_collection_backend() override { return collection_backend_; } CollectionModel *songs_collection_model() override { return collection_model_; } @@ -124,6 +125,7 @@ class SubsonicService : public InternetService { QUrl server_url_; QString username_; QString password_; + bool http2_; bool verify_certificate_; bool download_album_covers_;