mirror of https://github.com/KLayout/klayout.git
Fixed build with curl
This commit is contained in:
parent
245bf93429
commit
204cb7ec3f
|
|
@ -26,6 +26,30 @@
|
|||
namespace tl
|
||||
{
|
||||
|
||||
// .. nothing yet ..
|
||||
// ---------------------------------------------------------------
|
||||
// HttpErrorException implementation
|
||||
|
||||
std::string
|
||||
HttpErrorException::format_error (const std::string &em, int ec, const std::string &url, const std::string &body)
|
||||
{
|
||||
std::string msg = tl::sprintf (tl::to_string (tr ("Error %d: %s, fetching %s")), ec, em, url);
|
||||
|
||||
if (! body.empty ()) {
|
||||
|
||||
msg += "\n\n";
|
||||
msg += tl::to_string (tr ("Reply body:"));
|
||||
msg += "\n";
|
||||
|
||||
if (body.size () > 1000) {
|
||||
msg += std::string (body.c_str (), 1000);
|
||||
msg += "...";
|
||||
} else {
|
||||
msg += body;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,11 +56,11 @@ class TL_PUBLIC HttpErrorException
|
|||
: public tl::Exception
|
||||
{
|
||||
public:
|
||||
HttpErrorException (const std::string &f, int ec, QNetworkReply *reply)
|
||||
: tl::Exception (format_error (f, ec, reply))
|
||||
HttpErrorException (const std::string &f, int ec, const std::string &url, const std::string &body = std::string ())
|
||||
: tl::Exception (format_error (f, ec, url, body))
|
||||
{ }
|
||||
|
||||
static std::string format_error (const std::string &em, int ec, QNetworkReply *reply);
|
||||
static std::string format_error (const std::string &em, int ec, const std::string &url, const std::string &body);
|
||||
};
|
||||
|
||||
class InputHttpStreamPrivateData;
|
||||
|
|
|
|||
|
|
@ -123,39 +123,6 @@ AuthenticationHandler::proxyAuthenticationRequired (const QNetworkProxy &proxy,
|
|||
// ---------------------------------------------------------------
|
||||
// InputHttpStream implementation
|
||||
|
||||
std::string
|
||||
HttpErrorException::format_error (const std::string &em, int ec, QNetworkReply *reply)
|
||||
{
|
||||
std::string msg = tl::sprintf (tl::to_string (tr ("Error %d: %s, fetching %s")), ec, em, tl::to_string (reply->url ().toString ()));
|
||||
|
||||
std::string data = tl::to_string (QString::fromUtf8 (reply->readAll ()));
|
||||
if (data.size () > 1000) {
|
||||
data = data.substr (0, size_t (1000)) + "...";
|
||||
}
|
||||
|
||||
if (! data.empty ()) {
|
||||
|
||||
msg += "\n\n";
|
||||
msg += tl::to_string (tr ("Reply body:"));
|
||||
msg += "\n";
|
||||
msg += data;
|
||||
|
||||
}
|
||||
|
||||
std::string redirected = tl::to_string (reply->attribute (QNetworkRequest::RedirectionTargetAttribute).toString ());
|
||||
if (! redirected.empty ()) {
|
||||
|
||||
msg += "\n\n";
|
||||
msg += tl::to_string (tr ("Redirected to: ")) + redirected;
|
||||
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// InputHttpStream implementation
|
||||
|
||||
InputHttpStream::InputHttpStream (const std::string &url)
|
||||
{
|
||||
mp_data = new InputHttpStreamPrivateData (url);
|
||||
|
|
@ -482,7 +449,9 @@ InputHttpStreamPrivateData::read (char *b, size_t n)
|
|||
ec = int (mp_reply->error ());
|
||||
}
|
||||
|
||||
throw HttpErrorException (em, ec, mp_reply);
|
||||
QByteArray data = mp_reply->readAll ();
|
||||
|
||||
throw HttpErrorException (em, ec, tl::to_string (mp_reply->url ().toString ()), tl::to_string (data.constData (), (int)data.size ()));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue