From 615ba36836e780a5a6b28f87ab86955db4a6a380 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Thu, 12 Oct 2017 21:08:19 +0200 Subject: [PATCH] Bugfix: take download URL as source for packages also for relative URLs Plus: diagnostics for HTTP access. --- src/lay/lay/laySaltGrain.cc | 13 +++++++------ src/tl/tl/tlHttpStream.cc | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/lay/lay/laySaltGrain.cc b/src/lay/lay/laySaltGrain.cc index 4a8c061f1..e91c1ccef 100644 --- a/src/lay/lay/laySaltGrain.cc +++ b/src/lay/lay/laySaltGrain.cc @@ -472,30 +472,31 @@ SaltGrain::from_path (const std::string &path) } SaltGrain -SaltGrain::from_url (const std::string &url) +SaltGrain::from_url (const std::string &url_in) { - if (url.empty ()) { + if (url_in.empty ()) { throw tl::Exception (tl::to_string (QObject::tr ("No download link available"))); } + std::string url = url_in; std::auto_ptr stream; - std::string spec_url = SaltGrain::spec_url (url); // base relative URL's on the salt mine URL - if (spec_url.find ("http:") != 0 && spec_url.find ("https:") != 0 && spec_url.find ("file:") != 0 && !spec_url.empty() && spec_url[0] != '/' && spec_url[0] != '\\' && lay::SaltController::instance ()) { + if (url.find ("http:") != 0 && url.find ("https:") != 0 && url.find ("file:") != 0 && !url.empty() && url[0] != '/' && url[0] != '\\' && lay::SaltController::instance ()) { // replace the last component ("repository.xml") by the given path QUrl sami_url (tl::to_qstring (lay::SaltController::instance ()->salt_mine_url ())); QStringList path_comp = sami_url.path ().split (QString::fromUtf8 ("/")); if (!path_comp.isEmpty ()) { - path_comp.back () = tl::to_qstring (spec_url); + path_comp.back () = tl::to_qstring (url); } sami_url.setPath (path_comp.join (QString::fromUtf8 ("/"))); - spec_url = tl::to_string (sami_url.toString ()); + url = tl::to_string (sami_url.toString ()); } + std::string spec_url = SaltGrain::spec_url (url); if (spec_url.find ("http:") == 0 || spec_url.find ("https:") == 0) { stream.reset (tl::WebDAVObject::download_item (spec_url)); } else { diff --git a/src/tl/tl/tlHttpStream.cc b/src/tl/tl/tlHttpStream.cc index 8d707d0a6..26d33eb6a 100644 --- a/src/tl/tl/tlHttpStream.cc +++ b/src/tl/tl/tlHttpStream.cc @@ -22,6 +22,7 @@ #include "tlHttpStream.h" +#include "tlLog.h" #include "tlStaticObjects.h" #include "tlDeferredExecution.h" @@ -159,6 +160,9 @@ InputHttpStream::finished (QNetworkReply *reply) QVariant redirect_target = reply->attribute (QNetworkRequest::RedirectionTargetAttribute); if (reply->error () == QNetworkReply::NoError && ! redirect_target.isNull ()) { m_url = tl::to_string (redirect_target.toString ()); + if (tl::verbosity() >= 30) { + tl::info << "HTTP redirect to: " << m_url; + } issue_request (QUrl (redirect_target.toString ())); } else { mp_reply = reply; @@ -172,12 +176,21 @@ InputHttpStream::issue_request (const QUrl &url) mp_buffer = 0; QNetworkRequest request (url); + if (tl::verbosity() >= 30) { + tl::info << "HTTP request URL: " << url.toString ().toUtf8 ().constData (); + } for (std::map::const_iterator h = m_headers.begin (); h != m_headers.end (); ++h) { + if (tl::verbosity() >= 40) { + tl::info << "HTTP request header: " << h->first << ": " << h->second; + } request.setRawHeader (QByteArray (h->first.c_str ()), QByteArray (h->second.c_str ())); } if (m_data.isEmpty ()) { mp_active_reply.reset (s_network_manager->sendCustomRequest (request, m_request)); } else { + if (tl::verbosity() >= 40) { + tl::info << "HTTP request data: " << m_data.constData (); + } mp_buffer = new QBuffer (&m_data); mp_active_reply.reset (s_network_manager->sendCustomRequest (request, m_request, mp_buffer)); } @@ -201,6 +214,9 @@ InputHttpStream::read (char *b, size_t n) if (mp_reply->error () != QNetworkReply::NoError) { // throw an error std::string em = tl::to_string (mp_reply->attribute (QNetworkRequest::HttpReasonPhraseAttribute).toString ()); + if (tl::verbosity() >= 30) { + tl::info << "HTTP response error: " << em; + } int ec = mp_reply->attribute (QNetworkRequest::HttpStatusCodeAttribute).toInt (); if (ec == 0) { ec = int (mp_reply->error ()); @@ -211,6 +227,9 @@ InputHttpStream::read (char *b, size_t n) QByteArray data = mp_reply->read (n); memcpy (b, data.constData (), data.size ()); + if (tl::verbosity() >= 40) { + tl::info << "HTTP reponse data read: " << data.constData (); + } return data.size (); }