mirror of https://github.com/KLayout/klayout.git
Bugfix: take download URL as source for packages also for relative URLs
Plus: diagnostics for HTTP access.
This commit is contained in:
parent
b3ffa23499
commit
615ba36836
|
|
@ -472,30 +472,31 @@ SaltGrain::from_path (const std::string &path)
|
||||||
}
|
}
|
||||||
|
|
||||||
SaltGrain
|
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")));
|
throw tl::Exception (tl::to_string (QObject::tr ("No download link available")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string url = url_in;
|
||||||
std::auto_ptr<tl::InputStream> stream;
|
std::auto_ptr<tl::InputStream> stream;
|
||||||
std::string spec_url = SaltGrain::spec_url (url);
|
|
||||||
|
|
||||||
// base relative URL's on the salt mine 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
|
// replace the last component ("repository.xml") by the given path
|
||||||
QUrl sami_url (tl::to_qstring (lay::SaltController::instance ()->salt_mine_url ()));
|
QUrl sami_url (tl::to_qstring (lay::SaltController::instance ()->salt_mine_url ()));
|
||||||
QStringList path_comp = sami_url.path ().split (QString::fromUtf8 ("/"));
|
QStringList path_comp = sami_url.path ().split (QString::fromUtf8 ("/"));
|
||||||
if (!path_comp.isEmpty ()) {
|
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 ("/")));
|
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) {
|
if (spec_url.find ("http:") == 0 || spec_url.find ("https:") == 0) {
|
||||||
stream.reset (tl::WebDAVObject::download_item (spec_url));
|
stream.reset (tl::WebDAVObject::download_item (spec_url));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "tlHttpStream.h"
|
#include "tlHttpStream.h"
|
||||||
|
#include "tlLog.h"
|
||||||
#include "tlStaticObjects.h"
|
#include "tlStaticObjects.h"
|
||||||
#include "tlDeferredExecution.h"
|
#include "tlDeferredExecution.h"
|
||||||
|
|
||||||
|
|
@ -159,6 +160,9 @@ InputHttpStream::finished (QNetworkReply *reply)
|
||||||
QVariant redirect_target = reply->attribute (QNetworkRequest::RedirectionTargetAttribute);
|
QVariant redirect_target = reply->attribute (QNetworkRequest::RedirectionTargetAttribute);
|
||||||
if (reply->error () == QNetworkReply::NoError && ! redirect_target.isNull ()) {
|
if (reply->error () == QNetworkReply::NoError && ! redirect_target.isNull ()) {
|
||||||
m_url = tl::to_string (redirect_target.toString ());
|
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 ()));
|
issue_request (QUrl (redirect_target.toString ()));
|
||||||
} else {
|
} else {
|
||||||
mp_reply = reply;
|
mp_reply = reply;
|
||||||
|
|
@ -172,12 +176,21 @@ InputHttpStream::issue_request (const QUrl &url)
|
||||||
mp_buffer = 0;
|
mp_buffer = 0;
|
||||||
|
|
||||||
QNetworkRequest request (url);
|
QNetworkRequest request (url);
|
||||||
|
if (tl::verbosity() >= 30) {
|
||||||
|
tl::info << "HTTP request URL: " << url.toString ().toUtf8 ().constData ();
|
||||||
|
}
|
||||||
for (std::map<std::string, std::string>::const_iterator h = m_headers.begin (); h != m_headers.end (); ++h) {
|
for (std::map<std::string, std::string>::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 ()));
|
request.setRawHeader (QByteArray (h->first.c_str ()), QByteArray (h->second.c_str ()));
|
||||||
}
|
}
|
||||||
if (m_data.isEmpty ()) {
|
if (m_data.isEmpty ()) {
|
||||||
mp_active_reply.reset (s_network_manager->sendCustomRequest (request, m_request));
|
mp_active_reply.reset (s_network_manager->sendCustomRequest (request, m_request));
|
||||||
} else {
|
} else {
|
||||||
|
if (tl::verbosity() >= 40) {
|
||||||
|
tl::info << "HTTP request data: " << m_data.constData ();
|
||||||
|
}
|
||||||
mp_buffer = new QBuffer (&m_data);
|
mp_buffer = new QBuffer (&m_data);
|
||||||
mp_active_reply.reset (s_network_manager->sendCustomRequest (request, m_request, mp_buffer));
|
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) {
|
if (mp_reply->error () != QNetworkReply::NoError) {
|
||||||
// throw an error
|
// throw an error
|
||||||
std::string em = tl::to_string (mp_reply->attribute (QNetworkRequest::HttpReasonPhraseAttribute).toString ());
|
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 ();
|
int ec = mp_reply->attribute (QNetworkRequest::HttpStatusCodeAttribute).toInt ();
|
||||||
if (ec == 0) {
|
if (ec == 0) {
|
||||||
ec = int (mp_reply->error ());
|
ec = int (mp_reply->error ());
|
||||||
|
|
@ -211,6 +227,9 @@ InputHttpStream::read (char *b, size_t n)
|
||||||
|
|
||||||
QByteArray data = mp_reply->read (n);
|
QByteArray data = mp_reply->read (n);
|
||||||
memcpy (b, data.constData (), data.size ());
|
memcpy (b, data.constData (), data.size ());
|
||||||
|
if (tl::verbosity() >= 40) {
|
||||||
|
tl::info << "HTTP reponse data read: " << data.constData ();
|
||||||
|
}
|
||||||
return data.size ();
|
return data.size ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue